From 9cf82621b79f4aaa8ca2d675f4d56638768513c0 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Hugly Date: Mon, 4 Dec 2023 17:31:42 +0100 Subject: [PATCH] router: Reviwer's suggestions Changes: * Add helper function for boiler plate underlay layer construction. * Fix Fake MacAddresses to make them more deliberately fake. --- .../router_newbenchmark/cases/BUILD.bazel | 1 + .../router_newbenchmark/cases/br_transit.go | 38 ++++--------------- acceptance/router_newbenchmark/cases/in.go | 28 +------------- .../router_newbenchmark/cases/in_transit.go | 30 ++------------- acceptance/router_newbenchmark/cases/out.go | 28 +------------- .../router_newbenchmark/cases/out_transit.go | 30 ++------------- acceptance/router_newbenchmark/cases/topo.go | 37 ++++++++++++++++++ 7 files changed, 55 insertions(+), 137 deletions(-) diff --git a/acceptance/router_newbenchmark/cases/BUILD.bazel b/acceptance/router_newbenchmark/cases/BUILD.bazel index 154e776a3d..d7e13f435b 100644 --- a/acceptance/router_newbenchmark/cases/BUILD.bazel +++ b/acceptance/router_newbenchmark/cases/BUILD.bazel @@ -19,6 +19,7 @@ go_library( "//pkg/addr:go_default_library", "//pkg/private/util:go_default_library", "//pkg/private/xtest:go_default_library", + "//pkg/scrypto:go_default_library", "//pkg/slayers:go_default_library", "//pkg/slayers/path:go_default_library", "//pkg/slayers/path/scion:go_default_library", diff --git a/acceptance/router_newbenchmark/cases/br_transit.go b/acceptance/router_newbenchmark/cases/br_transit.go index 4cb43f08eb..789856ad61 100644 --- a/acceptance/router_newbenchmark/cases/br_transit.go +++ b/acceptance/router_newbenchmark/cases/br_transit.go @@ -19,7 +19,6 @@ import ( "time" "github.com/google/gopacket" - "github.com/google/gopacket/layers" "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/pkg/slayers" @@ -42,9 +41,7 @@ func oneBrTransit(payload string, mac hash.Hash, flowId uint32) []byte { originIP = PublicIP(2, 1) originHost = HostAddr(originIP) srcIP, srcPort = PublicIPPort(2, 1) - srcMAC = MACAddr(srcIP) dstIP, dstPort = PublicIPPort(1, 2) - dstMAC = MACAddr(dstIP) targetIA = ISDAS(3) targetIP = PublicIP(3, 1) targetHost = HostAddr(targetIP) @@ -55,28 +52,7 @@ func oneBrTransit(payload string, mac hash.Hash, flowId uint32) []byte { ComputeChecksums: true, } - // Point-to-point. - ethernet := &layers.Ethernet{ - SrcMAC: srcMAC, - DstMAC: dstMAC, - EthernetType: layers.EthernetTypeIPv4, - } - - // Point-to-point. This is the real IP: the underlay network. - ip := &layers.IPv4{ - Version: 4, - IHL: 5, - TTL: 64, - SrcIP: srcIP.AsSlice(), - DstIP: dstIP.AsSlice(), - Protocol: layers.IPProtocolUDP, - Flags: layers.IPv4DontFragment, - } - udp := &layers.UDP{ - SrcPort: srcPort, - DstPort: dstPort, - } - _ = udp.SetNetworkLayerForChecksum(ip) + ethernet, ip, udp := Underlay(srcIP, srcPort, dstIP, dstPort) // Fully correct (hopefully) path. sp := &scion.Decoded{ @@ -101,10 +77,10 @@ func oneBrTransit(payload string, mac hash.Hash, flowId uint32) []byte { }, }, HopFields: []path.HopField{ - {ConsIngress: 22, ConsEgress: 0}, // From there (non-consdir) - {ConsIngress: 0, ConsEgress: 2}, // <- Processed here (non-consdir) - {ConsIngress: 0, ConsEgress: 3}, // Down via this - {ConsIngress: 33, ConsEgress: 0}, // To there + {ConsIngress: 1, ConsEgress: 0}, // From there (non-consdir) + {ConsIngress: 0, ConsEgress: 2}, // <- Processed here (non-consdir) + {ConsIngress: 0, ConsEgress: 3}, // Down via this + {ConsIngress: 1, ConsEgress: 0}, // To there }, } @@ -112,12 +88,12 @@ func oneBrTransit(payload string, mac hash.Hash, flowId uint32) []byte { // Seg0: Hops are in non-consdir. sp.HopFields[1].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[1], nil) sp.InfoFields[0].UpdateSegID(sp.HopFields[1].Mac) - sp.HopFields[0].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil) + sp.HopFields[0].Mac = path.MAC(FakeMAC(2), sp.InfoFields[0], sp.HopFields[0], nil) // Seg1: in the natural order. sp.HopFields[2].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil) sp.InfoFields[1].UpdateSegID(sp.HopFields[2].Mac) // tmp - sp.HopFields[3].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil) + sp.HopFields[3].Mac = path.MAC(FakeMAC(3), sp.InfoFields[1], sp.HopFields[2], nil) sp.InfoFields[1].SegID = 0x222 // Restore to initial. // End-to-end. Src is the originator and Dst is the final destination. diff --git a/acceptance/router_newbenchmark/cases/in.go b/acceptance/router_newbenchmark/cases/in.go index 3943633ef9..bf760a2fb0 100644 --- a/acceptance/router_newbenchmark/cases/in.go +++ b/acceptance/router_newbenchmark/cases/in.go @@ -19,7 +19,6 @@ import ( "time" "github.com/google/gopacket" - "github.com/google/gopacket/layers" "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/pkg/slayers" @@ -42,9 +41,7 @@ func oneIn(payload string, mac hash.Hash, flowId uint32) []byte { originIP = PublicIP(2, 1) originHost = HostAddr(originIP) srcIP, srcPort = PublicIPPort(2, 1) - srcMAC = MACAddr(srcIP) dstIP, dstPort = PublicIPPort(1, 2) - dstMAC = MACAddr(dstIP) targetIA = ISDAS(1) targetIP = InternalIP(1, 2) targetHost = HostAddr(targetIP) @@ -55,28 +52,7 @@ func oneIn(payload string, mac hash.Hash, flowId uint32) []byte { ComputeChecksums: true, } - // Point-to-point. - ethernet := &layers.Ethernet{ - SrcMAC: srcMAC, - DstMAC: dstMAC, - EthernetType: layers.EthernetTypeIPv4, - } - - // Point-to-point. This is the real IP: the underlay network. - ip := &layers.IPv4{ - Version: 4, - IHL: 5, - TTL: 64, - SrcIP: srcIP.AsSlice(), - DstIP: dstIP.AsSlice(), - Protocol: layers.IPProtocolUDP, - Flags: layers.IPv4DontFragment, - } - udp := &layers.UDP{ - SrcPort: srcPort, - DstPort: dstPort, - } - _ = udp.SetNetworkLayerForChecksum(ip) + ethernet, ip, udp := Underlay(srcIP, srcPort, dstIP, dstPort) // Fully correct (hopefully) path. sp := &scion.Decoded{ @@ -105,7 +81,7 @@ func oneIn(payload string, mac hash.Hash, flowId uint32) []byte { // Seg0: Hops are in non-consdir. sp.HopFields[1].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[1], nil) sp.InfoFields[0].UpdateSegID(sp.HopFields[1].Mac) - sp.HopFields[0].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil) + sp.HopFields[0].Mac = path.MAC(FakeMAC(2), sp.InfoFields[0], sp.HopFields[0], nil) // End-to-end. Src is the originator and Dst is the final destination. scionL := &slayers.SCION{ diff --git a/acceptance/router_newbenchmark/cases/in_transit.go b/acceptance/router_newbenchmark/cases/in_transit.go index 84c51f954e..de51f87d7a 100644 --- a/acceptance/router_newbenchmark/cases/in_transit.go +++ b/acceptance/router_newbenchmark/cases/in_transit.go @@ -19,7 +19,6 @@ import ( "time" "github.com/google/gopacket" - "github.com/google/gopacket/layers" "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/pkg/slayers" @@ -42,9 +41,7 @@ func oneInTransit(payload string, mac hash.Hash, flowId uint32) []byte { originIP = PublicIP(2, 1) originHost = HostAddr(originIP) srcIP, srcPort = PublicIPPort(2, 1) - srcMAC = MACAddr(srcIP) dstIP, dstPort = PublicIPPort(1, 2) - dstMAC = MACAddr(dstIP) targetIA = ISDAS(4) targetIP = PublicIP(4, 1) targetHost = HostAddr(targetIP) @@ -55,28 +52,7 @@ func oneInTransit(payload string, mac hash.Hash, flowId uint32) []byte { ComputeChecksums: true, } - // Point-to-point. - ethernet := &layers.Ethernet{ - SrcMAC: srcMAC, - DstMAC: dstMAC, - EthernetType: layers.EthernetTypeIPv4, - } - - // Point-to-point. This is the real IP: the underlay network. - ip := &layers.IPv4{ - Version: 4, - IHL: 5, - TTL: 64, - SrcIP: srcIP.AsSlice(), - DstIP: dstIP.AsSlice(), - Protocol: layers.IPProtocolUDP, - Flags: layers.IPv4DontFragment, - } - udp := &layers.UDP{ - SrcPort: srcPort, - DstPort: dstPort, - } - _ = udp.SetNetworkLayerForChecksum(ip) + ethernet, ip, udp := Underlay(srcIP, srcPort, dstIP, dstPort) // Fully correct (hopefully) path. sp := &scion.Decoded{ @@ -112,12 +88,12 @@ func oneInTransit(payload string, mac hash.Hash, flowId uint32) []byte { // Seg0: Hops are in non-consdir. sp.HopFields[1].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[1], nil) sp.InfoFields[0].UpdateSegID(sp.HopFields[1].Mac) - sp.HopFields[0].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil) + sp.HopFields[0].Mac = path.MAC(FakeMAC(2), sp.InfoFields[0], sp.HopFields[0], nil) // Seg1: in the natural order. sp.HopFields[2].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil) sp.InfoFields[1].UpdateSegID(sp.HopFields[2].Mac) // tmp - sp.HopFields[3].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil) + sp.HopFields[3].Mac = path.MAC(FakeMAC(4), sp.InfoFields[1], sp.HopFields[2], nil) sp.InfoFields[1].SegID = 0x222 // Restore to initial. // End-to-end. Src is the originator and Dst is the final destination. diff --git a/acceptance/router_newbenchmark/cases/out.go b/acceptance/router_newbenchmark/cases/out.go index aff0606a57..0f36ca5267 100644 --- a/acceptance/router_newbenchmark/cases/out.go +++ b/acceptance/router_newbenchmark/cases/out.go @@ -19,7 +19,6 @@ import ( "time" "github.com/google/gopacket" - "github.com/google/gopacket/layers" "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/pkg/slayers" @@ -42,9 +41,7 @@ func oneOut(payload string, mac hash.Hash, flowId uint32) []byte { originIP = InternalIP(1, 2) originHost = HostAddr(originIP) srcIP, srcPort = InternalIPPort(1, 2) - srcMAC = MACAddr(srcIP) dstIP, dstPort = InternalIPPort(1, 1) - dstMAC = MACAddr(dstIP) targetIA = ISDAS(2) targetIP = PublicIP(2, 1) targetHost = HostAddr(targetIP) @@ -55,28 +52,7 @@ func oneOut(payload string, mac hash.Hash, flowId uint32) []byte { ComputeChecksums: true, } - // Point-to-point. - ethernet := &layers.Ethernet{ - SrcMAC: srcMAC, - DstMAC: dstMAC, - EthernetType: layers.EthernetTypeIPv4, - } - - // Point-to-point. This is the real IP: the underlay network. - ip := &layers.IPv4{ - Version: 4, - IHL: 5, - TTL: 64, - SrcIP: srcIP.AsSlice(), - DstIP: dstIP.AsSlice(), - Protocol: layers.IPProtocolUDP, - Flags: layers.IPv4DontFragment, - } - udp := &layers.UDP{ - SrcPort: srcPort, - DstPort: dstPort, - } - _ = udp.SetNetworkLayerForChecksum(ip) + ethernet, ip, udp := Underlay(srcIP, srcPort, dstIP, dstPort) // Fully correct (hopefully) path. sp := &scion.Decoded{ @@ -105,7 +81,7 @@ func oneOut(payload string, mac hash.Hash, flowId uint32) []byte { // Seg0: Hops are in consdir. sp.HopFields[0].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil) sp.InfoFields[0].UpdateSegID(sp.HopFields[0].Mac) // tmp - sp.HopFields[1].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil) + sp.HopFields[1].Mac = path.MAC(FakeMAC(2), sp.InfoFields[0], sp.HopFields[0], nil) sp.InfoFields[0].SegID = 0x111 // Restore to initial. // End-to-end. Src is the originator and Dst is the final destination. diff --git a/acceptance/router_newbenchmark/cases/out_transit.go b/acceptance/router_newbenchmark/cases/out_transit.go index 1618c5eba4..5322ce4950 100644 --- a/acceptance/router_newbenchmark/cases/out_transit.go +++ b/acceptance/router_newbenchmark/cases/out_transit.go @@ -19,7 +19,6 @@ import ( "time" "github.com/google/gopacket" - "github.com/google/gopacket/layers" "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/pkg/slayers" @@ -42,9 +41,7 @@ func oneOutTransit(payload string, mac hash.Hash, flowId uint32) []byte { originIP = PublicIP(4, 1) originHost = HostAddr(originIP) srcIP, srcPort = InternalIPPort(1, 2) - srcMAC = MACAddr(srcIP) dstIP, dstPort = InternalIPPort(1, 1) - dstMAC = MACAddr(dstIP) targetIA = ISDAS(2) targetIP = PublicIP(2, 1) targetHost = HostAddr(targetIP) @@ -55,28 +52,7 @@ func oneOutTransit(payload string, mac hash.Hash, flowId uint32) []byte { ComputeChecksums: true, } - // Point-to-point. - ethernet := &layers.Ethernet{ - SrcMAC: srcMAC, - DstMAC: dstMAC, - EthernetType: layers.EthernetTypeIPv4, - } - - // Point-to-point. This is the real IP: the underlay network. - ip := &layers.IPv4{ - Version: 4, - IHL: 5, - TTL: 64, - SrcIP: srcIP.AsSlice(), - DstIP: dstIP.AsSlice(), - Protocol: layers.IPProtocolUDP, - Flags: layers.IPv4DontFragment, - } - udp := &layers.UDP{ - SrcPort: srcPort, - DstPort: dstPort, - } - _ = udp.SetNetworkLayerForChecksum(ip) + ethernet, ip, udp := Underlay(srcIP, srcPort, dstIP, dstPort) // Fully correct (hopefully) path. sp := &scion.Decoded{ @@ -113,12 +89,12 @@ func oneOutTransit(payload string, mac hash.Hash, flowId uint32) []byte { // Seg0: Hops are in non-consdir. sp.HopFields[1].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[1], nil) sp.InfoFields[0].UpdateSegID(sp.HopFields[1].Mac) - sp.HopFields[0].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil) + sp.HopFields[0].Mac = path.MAC(FakeMAC(4), sp.InfoFields[0], sp.HopFields[0], nil) // Seg1: in the natural order. sp.HopFields[2].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil) sp.InfoFields[1].UpdateSegID(sp.HopFields[2].Mac) // tmp - sp.HopFields[3].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil) + sp.HopFields[3].Mac = path.MAC(FakeMAC(2), sp.InfoFields[1], sp.HopFields[2], nil) sp.InfoFields[1].SegID = 0x222 // Restore to initial. // End-to-end. Src is the originator and Dst is the final destination. diff --git a/acceptance/router_newbenchmark/cases/topo.go b/acceptance/router_newbenchmark/cases/topo.go index 647a4cce1d..da78ab2401 100644 --- a/acceptance/router_newbenchmark/cases/topo.go +++ b/acceptance/router_newbenchmark/cases/topo.go @@ -16,6 +16,7 @@ package cases import ( "fmt" + "hash" "net" "net/netip" "strings" @@ -24,6 +25,7 @@ import ( "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/private/xtest" + "github.com/scionproto/scion/pkg/scrypto" ) // Topology (see accept/router_newbenchmark/conf/topology.json) @@ -95,6 +97,41 @@ func ISDAS(AS byte) addr.IA { return xtest.MustParseIA(fmt.Sprintf("1-ff00:0:%d", AS)) } +func FakeMAC(AS byte) hash.Hash { + macGen, err := scrypto.HFMacFactory([]byte{AS}) + if err != nil { + panic(err) + } + return macGen() +} + +func Underlay(srcIP netip.Addr, srcPort layers.UDPPort, dstIP netip.Addr, dstPort layers.UDPPort) (*layers.Ethernet, *layers.IPv4, *layers.UDP) { + // Point-to-point. + ethernet := &layers.Ethernet{ + SrcMAC: MACAddr(srcIP), + DstMAC: MACAddr(dstIP), + EthernetType: layers.EthernetTypeIPv4, + } + + // Point-to-point. This is the real IP: the underlay network. + ip := &layers.IPv4{ + Version: 4, + IHL: 5, + TTL: 64, + SrcIP: srcIP.AsSlice(), + DstIP: dstIP.AsSlice(), + Protocol: layers.IPProtocolUDP, + Flags: layers.IPv4DontFragment, + } + udp := &layers.UDP{ + SrcPort: srcPort, + DstPort: dstPort, + } + _ = udp.SetNetworkLayerForChecksum(ip) + + return ethernet, ip, udp +} + // interfaceLabel returns a string label for the given AS and interface indices. // Such names are those used when responding to the show-interfaces command and when translating // the --interface option.