Skip to content

Commit

Permalink
router: Reviwer's suggestions
Browse files Browse the repository at this point in the history
Changes:
* Add helper function for boiler plate underlay layer construction.
* Fix Fake MacAddresses to make them more deliberately fake.
  • Loading branch information
jiceatscion committed Dec 4, 2023
1 parent 7b25bf4 commit 9cf8262
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 137 deletions.
1 change: 1 addition & 0 deletions acceptance/router_newbenchmark/cases/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 7 additions & 31 deletions acceptance/router_newbenchmark/cases/br_transit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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{
Expand All @@ -101,23 +77,23 @@ 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
},
}

// Calculate MACs...
// 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.
Expand Down
28 changes: 2 additions & 26 deletions acceptance/router_newbenchmark/cases/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
30 changes: 3 additions & 27 deletions acceptance/router_newbenchmark/cases/in_transit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
28 changes: 2 additions & 26 deletions acceptance/router_newbenchmark/cases/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 3 additions & 27 deletions acceptance/router_newbenchmark/cases/out_transit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 37 additions & 0 deletions acceptance/router_newbenchmark/cases/topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cases

import (
"fmt"
"hash"
"net"
"net/netip"
"strings"
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9cf8262

Please sign in to comment.