-
Notifications
You must be signed in to change notification settings - Fork 162
/
child_to_child_peering_in.go
176 lines (156 loc) · 5.67 KB
/
child_to_child_peering_in.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright 2020 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cases
import (
"hash"
"net"
"path/filepath"
"time"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/private/util"
"github.com/scionproto/scion/pkg/private/xtest"
"github.com/scionproto/scion/pkg/slayers"
"github.com/scionproto/scion/pkg/slayers/path"
"github.com/scionproto/scion/pkg/slayers/path/scion"
"github.com/scionproto/scion/tools/braccept/runner"
)
// ChildToChildPeeringIn tests transit traffic over one BR host and one peering hop.
// In this case, traffic enters via a peering link, and leaves via a regular link from
// the same router. To be valid, the path as to be constructed as one single hop up
// segment at the peering link origin and one down segment over the regular link.
// The peering hop is the first hop on the second segment: it crosses from a peering
// interface to a child interface.
func ChildToChildPeeringIn(artifactsDir string, mac hash.Hash) runner.Case {
options := gopacket.SerializeOptions{
FixLengths: true,
ComputeChecksums: true,
}
// We inject the packet into A (at I/F 121) as if coming from 2 (at I/F 211)
ethernet := &layers.Ethernet{
SrcMAC: net.HardwareAddr{0xf0, 0x0d, 0xca, 0xfe, 0xbe, 0xef}, // I/F 211
DstMAC: net.HardwareAddr{0xf0, 0x0d, 0xca, 0xfe, 0x00, 0x12}, // I/F 121
EthernetType: layers.EthernetTypeIPv4,
}
ip := &layers.IPv4{ // On the 2->A link
Version: 4,
IHL: 5,
TTL: 64,
SrcIP: net.IP{192, 168, 12, 3}, // from 2's 211 IP
DstIP: net.IP{192, 168, 12, 2}, // to A's 121 IP
Protocol: layers.IPProtocolUDP,
Flags: layers.IPv4DontFragment,
}
udp := &layers.UDP{
SrcPort: layers.UDPPort(40000),
DstPort: layers.UDPPort(50000),
}
_ = udp.SetNetworkLayerForChecksum(ip)
sp := &scion.Decoded{
Base: scion.Base{
PathMeta: scion.MetaHdr{
CurrHF: 1,
CurrINF: 1,
SegLen: [3]uint8{1, 2, 0},
},
NumINF: 2,
NumHops: 3,
},
InfoFields: []path.InfoField{
// up seg
{
SegID: 0x111,
ConsDir: false,
Timestamp: util.TimeToSecs(time.Now()),
},
// down seg
{
SegID: 0x222,
ConsDir: true,
Timestamp: util.TimeToSecs(time.Now()),
Peer: true,
},
},
HopFields: []path.HopField{
{ConsIngress: 211, ConsEgress: 0}, // at 2 out to A
{ConsIngress: 121, ConsEgress: 151}, // at A in from 2 out to 5
{ConsIngress: 511, ConsEgress: 0}, // at 5 in from A
},
}
// Make the packet look the way it should. HF[0] is a regular hop.
sp.HopFields[0].Mac = path.MAC(mac, sp.InfoFields[0], sp.HopFields[0], nil)
// HF[1] is a peering hop so it has the same SegID acc value as the next one
// in construction direction, HF[2]. Therefore, SEG[1]'s SegID.
sp.HopFields[1].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[1], nil)
sp.HopFields[2].Mac = path.MAC(mac, sp.InfoFields[1], sp.HopFields[2], nil)
// The message if ready for injest at A, that is at HF[1], the start of the
// second segment, in construction direction. So SegID is already correct.
// The end-to-end trip is from 2,172.16.2.1 to 5,172.16.5.1
// That won't change through forwarding.
scionL := &slayers.SCION{
Version: 0,
TrafficClass: 0xb8,
FlowID: 0xdead,
NextHdr: slayers.L4UDP,
PathType: scion.PathType,
SrcIA: xtest.MustParseIA("1-ff00:0:2"),
DstIA: xtest.MustParseIA("1-ff00:0:5"),
Path: sp,
}
if err := scionL.SetSrcAddr(addr.MustParseHost("172.16.2.1")); err != nil {
panic(err)
}
if err := scionL.SetDstAddr(addr.MustParseHost("174.16.5.1")); err != nil {
panic(err)
}
scionudp := &slayers.UDP{}
scionudp.SrcPort = 40111
scionudp.DstPort = 40222
scionudp.SetNetworkLayerForChecksum(scionL)
payload := []byte("actualpayloadbytes")
// Prepare input packet
input := gopacket.NewSerializeBuffer()
if err := gopacket.SerializeLayers(input, options,
ethernet, ip, udp, scionL, scionudp, gopacket.Payload(payload),
); err != nil {
panic(err)
}
// Prepare want packet
// We expect it out of A's 151 I/F on its way to 5's 511 I/F.
want := gopacket.NewSerializeBuffer()
ethernet.SrcMAC = net.HardwareAddr{0xf0, 0x0d, 0xca, 0xfe, 0x00, 0x15} // I/F 151
ethernet.DstMAC = net.HardwareAddr{0xf0, 0x0d, 0xca, 0xfe, 0xbe, 0xef} // I/F 511
ip.SrcIP = net.IP{192, 168, 15, 2} // from A's 151 IP
ip.DstIP = net.IP{192, 168, 15, 3} // to 5's 511 IP
udp.SrcPort, udp.DstPort = udp.DstPort, udp.SrcPort
if err := sp.IncPath(); err != nil {
panic(err)
}
// Out of A, the current segment is seg 1. The Current acc
// value is still the same since HF[1] is a peering hop.
if err := gopacket.SerializeLayers(want, options,
ethernet, ip, udp, scionL, scionudp, gopacket.Payload(payload),
); err != nil {
panic(err)
}
return runner.Case{
Name: "ChildToChildPeeringTransit",
WriteTo: "veth_121_host", // Where we inject the test packet
ReadFrom: "veth_151_host", // Where we capture the forwarded packet
Input: input.Bytes(),
Want: want.Bytes(),
StoreDir: filepath.Join(artifactsDir, "ChildToChildXover"),
}
}