blob: 9d8660638e00ac33b866348d3d7c6d8f65893907 [file] [log] [blame]
Yi Tseng7a38f9a2017-06-09 14:36:40 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tseng7a38f9a2017-06-09 14:36:40 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.dhcprelay;
17
Yi Tseng51f1be92017-09-01 17:24:57 -070018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070020import com.google.common.collect.ImmutableList;
21import com.google.common.collect.ImmutableSet;
22import com.google.common.collect.Lists;
23import com.google.common.collect.Maps;
24import com.google.common.collect.Sets;
Yi Tseng525ff402017-10-23 19:39:39 -070025import com.google.common.collect.Streams;
Yi Tseng51f1be92017-09-01 17:24:57 -070026import com.google.common.io.Resources;
Yi Tseng440e2b72017-08-24 14:47:34 -070027import org.apache.commons.io.Charsets;
Yi Tseng25bfe372017-11-03 16:27:32 -070028import org.apache.commons.lang3.tuple.Pair;
Yi Tseng51f1be92017-09-01 17:24:57 -070029import org.easymock.Capture;
30import org.easymock.CaptureType;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070031import org.easymock.EasyMock;
32import org.junit.After;
33import org.junit.Before;
34import org.junit.Test;
35import org.onlab.packet.ARP;
36import org.onlab.packet.DHCP;
Yi Tseng3df7f9d2017-08-17 13:08:31 -070037import org.onlab.packet.DeserializationException;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070038import org.onlab.packet.Ethernet;
39import org.onlab.packet.IPv4;
40import org.onlab.packet.Ip4Address;
Kalhee Kim45fede42017-09-05 19:05:06 +000041import org.onlab.packet.Ip6Address;
42import org.onlab.packet.IpPrefix;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070043import org.onlab.packet.IpAddress;
44import org.onlab.packet.MacAddress;
45import org.onlab.packet.UDP;
46import org.onlab.packet.VlanId;
47import org.onlab.packet.dhcp.CircuitId;
48import org.onlab.packet.dhcp.DhcpOption;
49import org.onlab.packet.dhcp.DhcpRelayAgentOption;
Kalhee Kim45fede42017-09-05 19:05:06 +000050import org.onlab.packet.dhcp.Dhcp6InterfaceIdOption;
51import org.onlab.packet.dhcp.Dhcp6RelayOption;
52import org.onlab.packet.dhcp.Dhcp6IaNaOption;
53import org.onlab.packet.dhcp.Dhcp6IaPdOption;
54import org.onlab.packet.dhcp.Dhcp6IaAddressOption;
55import org.onlab.packet.dhcp.Dhcp6IaPrefixOption;
56import org.onlab.packet.dhcp.Dhcp6Option;
Kalhee Kim495c9b22017-11-07 16:32:09 +000057import org.onlab.packet.dhcp.Dhcp6ClientIdOption;
58import org.onlab.packet.dhcp.Dhcp6Duid;
Kalhee Kimd94ceea2017-11-29 19:03:02 +000059import org.onosproject.dhcprelay.store.DhcpRelayStore;
60import org.onosproject.dhcprelay.store.DhcpRecord;
61import org.onosproject.dhcprelay.store.DhcpRelayStoreEvent;
62import org.onosproject.dhcprelay.store.DhcpRelayCounters;
63import org.onosproject.dhcprelay.store.DhcpRelayCountersStore;
Kalhee Kim45fede42017-09-05 19:05:06 +000064import org.onosproject.net.ConnectPoint;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070065import org.onosproject.TestApplicationId;
66import org.onosproject.cfg.ComponentConfigService;
67import org.onosproject.core.ApplicationId;
68import org.onosproject.core.CoreService;
Yi Tseng483ac6f2017-08-02 15:03:31 -070069import org.onosproject.dhcprelay.config.DefaultDhcpRelayConfig;
70import org.onosproject.dhcprelay.config.DhcpServerConfig;
Yi Tseng51f1be92017-09-01 17:24:57 -070071import org.onosproject.dhcprelay.config.IgnoreDhcpConfig;
Yi Tseng483ac6f2017-08-02 15:03:31 -070072import org.onosproject.dhcprelay.config.IndirectDhcpRelayConfig;
Yi Tseng127ffe52017-09-12 15:55:17 -070073import org.onosproject.net.Device;
Yi Tseng51f1be92017-09-01 17:24:57 -070074import org.onosproject.net.DeviceId;
Yi Tseng127ffe52017-09-12 15:55:17 -070075import org.onosproject.net.behaviour.Pipeliner;
76import org.onosproject.net.device.DeviceEvent;
77import org.onosproject.net.device.DeviceService;
Yi Tseng51f1be92017-09-01 17:24:57 -070078import org.onosproject.net.flow.DefaultTrafficSelector;
79import org.onosproject.net.flow.DefaultTrafficTreatment;
80import org.onosproject.net.flow.TrafficSelector;
Yi Tseng51f1be92017-09-01 17:24:57 -070081import org.onosproject.net.flowobjective.FlowObjectiveService;
82import org.onosproject.net.flowobjective.ForwardingObjective;
83import org.onosproject.net.flowobjective.Objective;
Yi Tsengaa417a62017-09-08 17:22:51 -070084import org.onosproject.net.host.HostProviderService;
Ray Milkeyfacf2862017-08-03 11:58:29 -070085import org.onosproject.net.intf.Interface;
86import org.onosproject.net.intf.InterfaceServiceAdapter;
Yi Tseng51f1be92017-09-01 17:24:57 -070087import org.onosproject.net.packet.PacketPriority;
Ray Milkey69ec8712017-08-08 13:00:43 -070088import org.onosproject.routeservice.Route;
89import org.onosproject.routeservice.RouteStoreAdapter;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070090import org.onosproject.net.DefaultHost;
91import org.onosproject.net.Host;
92import org.onosproject.net.HostId;
93import org.onosproject.net.HostLocation;
94import org.onosproject.net.config.NetworkConfigRegistry;
95import org.onosproject.net.host.HostDescription;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070096import org.onosproject.net.host.HostService;
Yi Tseng7a38f9a2017-06-09 14:36:40 -070097import org.onosproject.net.host.InterfaceIpAddress;
98import org.onosproject.net.packet.DefaultInboundPacket;
99import org.onosproject.net.packet.InboundPacket;
100import org.onosproject.net.packet.OutboundPacket;
101import org.onosproject.net.packet.PacketContext;
102import org.onosproject.net.packet.PacketContextAdapter;
103import org.onosproject.net.packet.PacketProcessor;
104import org.onosproject.net.packet.PacketServiceAdapter;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700105import org.onosproject.store.StoreDelegate;
Kalhee Kimba366062017-11-07 16:32:09 +0000106
107
108
109
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700110import org.osgi.service.component.ComponentContext;
Kalhee Kim45fede42017-09-05 19:05:06 +0000111import org.onlab.packet.DHCP6;
112import org.onlab.packet.IPv6;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700113
Yi Tseng127ffe52017-09-12 15:55:17 -0700114import java.io.IOException;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700115import java.nio.ByteBuffer;
116import java.util.Collection;
117import java.util.Dictionary;
118import java.util.List;
Kalhee Kim45fede42017-09-05 19:05:06 +0000119import java.util.ArrayList;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700120import java.util.Map;
121import java.util.Optional;
122import java.util.Set;
123import java.util.stream.Collectors;
124
125import static org.easymock.EasyMock.*;
126import static org.junit.Assert.*;
Yi Tseng51f1be92017-09-01 17:24:57 -0700127import static org.onosproject.dhcprelay.DhcpRelayManager.DHCP_RELAY_APP;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700128
129public class DhcpRelayManagerTest {
Kalhee Kima0b8f652017-10-18 22:00:30 +0000130 private static final short VLAN_LEN = 2;
131 private static final short SEPARATOR_LEN = 1;
Yi Tseng51f1be92017-09-01 17:24:57 -0700132 private static final String CONFIG_FILE_PATH = "dhcp-relay.json";
133 private static final DeviceId DEV_1_ID = DeviceId.deviceId("of:0000000000000001");
134 private static final DeviceId DEV_2_ID = DeviceId.deviceId("of:0000000000000002");
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700135 // Ip address for interfaces
136 private static final InterfaceIpAddress INTERFACE_IP = InterfaceIpAddress.valueOf("10.0.3.254/32");
Kalhee Kim45fede42017-09-05 19:05:06 +0000137 private static final InterfaceIpAddress INTERFACE_IP_V6 = InterfaceIpAddress.valueOf("2001:db8:1::254/128");
138 private static final List<InterfaceIpAddress> INTERFACE_IPS = ImmutableList.of(INTERFACE_IP, INTERFACE_IP_V6);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700139
140 // DHCP client (will send without option 82)
141 private static final Ip4Address IP_FOR_CLIENT = Ip4Address.valueOf("10.0.0.1");
Kalhee Kim45fede42017-09-05 19:05:06 +0000142 private static final Ip6Address IP_FOR_CLIENT_V6 = Ip6Address.valueOf("2001:db8:1::110");
143 private static final IpPrefix PREFIX_FOR_CLIENT_V6 = IpPrefix.valueOf("2001:db8:10::/56");
144 private static final IpPrefix PREFIX_FOR_ZERO = IpPrefix.valueOf("::/0");
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700145 private static final MacAddress CLIENT_MAC = MacAddress.valueOf("00:00:00:00:00:01");
146 private static final VlanId CLIENT_VLAN = VlanId.vlanId("100");
147 private static final ConnectPoint CLIENT_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/1");
148 private static final MacAddress CLIENT_IFACE_MAC = MacAddress.valueOf("00:00:00:00:11:01");
Yi Tsengaa417a62017-09-08 17:22:51 -0700149 private static final HostLocation CLIENT_LOCATION = new HostLocation(CLIENT_CP, 0);
150 private static final HostId CLIENT_HOST_ID = HostId.hostId(CLIENT_MAC, CLIENT_VLAN);
151 private static final Ip6Address CLIENT_LL_IP_V6 = Ip6Address.valueOf("fe80::200:00ff:fe00:0001");
Charles Chand988c282017-09-12 17:09:32 -0700152 private static final Host EXISTS_HOST = new DefaultHost(Dhcp4HandlerImpl.PROVIDER_ID,
Yi Tsengaa417a62017-09-08 17:22:51 -0700153 CLIENT_HOST_ID, CLIENT_MAC, CLIENT_VLAN,
154 CLIENT_LOCATION, ImmutableSet.of(CLIENT_LL_IP_V6));
Yi Tseng4025a102017-09-30 11:35:42 +0800155 private static final Interface CLIENT_INTERFACE = createInterface("C1",
156 CLIENT_CP,
157 INTERFACE_IPS,
158 CLIENT_IFACE_MAC,
159 CLIENT_VLAN,
160 null);
161
162
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700163
Yi Tsengaa417a62017-09-08 17:22:51 -0700164 // Dual homing test
165 private static final ConnectPoint CLIENT_DH_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/3");
166 private static final HostLocation CLIENT_DH_LOCATION = new HostLocation(CLIENT_DH_CP, 0);
Yi Tseng4025a102017-09-30 11:35:42 +0800167 private static final Interface CLIENT_DH_INTERFACE = createInterface("C1-DH",
168 CLIENT_DH_CP,
169 INTERFACE_IPS,
170 CLIENT_IFACE_MAC,
171 CLIENT_VLAN,
172 null);
Yi Tsengaa417a62017-09-08 17:22:51 -0700173
174
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700175 // DHCP client 2 (will send with option 82, so the vlan should equals to vlan from server)
176 private static final MacAddress CLIENT2_MAC = MacAddress.valueOf("00:00:00:00:00:01");
177 private static final VlanId CLIENT2_VLAN = VlanId.NONE;
Yi Tseng4025a102017-09-30 11:35:42 +0800178 private static final VlanId CLIENT2_VLAN_NATIVE = VlanId.vlanId("20");
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700179 private static final ConnectPoint CLIENT2_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/2");
180 private static final MacAddress CLIENT2_IFACE_MAC = MacAddress.valueOf("00:00:00:00:11:01");
Yi Tseng4025a102017-09-30 11:35:42 +0800181 private static final Interface CLIENT2_INTERFACE = createInterface("C2",
182 CLIENT2_CP,
183 INTERFACE_IPS,
184 CLIENT2_IFACE_MAC,
185 CLIENT2_VLAN,
186 CLIENT2_VLAN_NATIVE);
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000187 private static final VlanId CLIENT_BOGUS_VLAN = VlanId.vlanId("108");
188
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700189 // Outer relay information
Kalhee Kim121ba922017-11-01 17:56:44 +0000190 private static final Ip4Address OUTER_RELAY_IP = Ip4Address.valueOf("10.0.6.253");
Kalhee Kim45fede42017-09-05 19:05:06 +0000191 private static final Ip6Address OUTER_RELAY_IP_V6 = Ip6Address.valueOf("2001:db8:1::4");
Kalhee Kim121ba922017-11-01 17:56:44 +0000192 private static final Ip6Address OUTER_RELAY_LL_IP_V6 = Ip6Address.valueOf("fe80::200:0102:0304:0501");
193 private static final Set<IpAddress> OUTER_RELAY_IPS = ImmutableSet.of(OUTER_RELAY_IP,
194 OUTER_RELAY_IP_V6,
195 OUTER_RELAY_LL_IP_V6);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700196 private static final MacAddress OUTER_RELAY_MAC = MacAddress.valueOf("00:01:02:03:04:05");
197 private static final VlanId OUTER_RELAY_VLAN = VlanId.NONE;
198 private static final ConnectPoint OUTER_RELAY_CP = ConnectPoint.deviceConnectPoint("of:0000000000000001/2");
199 private static final HostLocation OUTER_REPLAY_HL = new HostLocation(OUTER_RELAY_CP, 0);
200 private static final HostId OUTER_RELAY_HOST_ID = HostId.hostId(OUTER_RELAY_MAC, OUTER_RELAY_VLAN);
Charles Chand988c282017-09-12 17:09:32 -0700201 private static final Host OUTER_RELAY_HOST = new DefaultHost(Dhcp4HandlerImpl.PROVIDER_ID,
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700202 OUTER_RELAY_HOST_ID,
203 OUTER_RELAY_MAC,
204 OUTER_RELAY_VLAN,
205 OUTER_REPLAY_HL,
206 OUTER_RELAY_IPS);
207
208 // DHCP Server
209 private static final MacAddress SERVER_MAC = MacAddress.valueOf("00:00:00:00:00:01");
210 private static final VlanId SERVER_VLAN = VlanId.NONE;
Yi Tseng4025a102017-09-30 11:35:42 +0800211 private static final VlanId SERVER_VLAN_NATIVE = VlanId.vlanId("10");
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700212 private static final ConnectPoint SERVER_CONNECT_POINT =
213 ConnectPoint.deviceConnectPoint("of:0000000000000001/5");
214 private static final HostLocation SERVER_LOCATION =
215 new HostLocation(SERVER_CONNECT_POINT, 0);
Kalhee Kim45fede42017-09-05 19:05:06 +0000216 private static final Ip4Address GATEWAY_IP = Ip4Address.valueOf("10.0.5.253");
217 private static final Ip6Address GATEWAY_IP_V6 = Ip6Address.valueOf("2000::105:253");
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700218 private static final Ip4Address SERVER_IP = Ip4Address.valueOf("10.0.3.253");
Kalhee Kim45fede42017-09-05 19:05:06 +0000219 private static final Ip6Address SERVER_IP_V6 = Ip6Address.valueOf("2000::103:253");
220 private static final Ip6Address SERVER_IP_V6_MCAST = Ip6Address.valueOf("ff02::1:2");
221 private static final Set<IpAddress> DHCP_SERVER_IPS = ImmutableSet.of(SERVER_IP, SERVER_IP_V6);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700222 private static final HostId SERVER_HOST_ID = HostId.hostId(SERVER_MAC, SERVER_VLAN);
Charles Chand988c282017-09-12 17:09:32 -0700223 private static final Host SERVER_HOST = new DefaultHost(Dhcp4HandlerImpl.PROVIDER_ID,
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700224 SERVER_HOST_ID,
225 SERVER_MAC,
226 SERVER_VLAN,
227 SERVER_LOCATION,
228 DHCP_SERVER_IPS);
229 private static final MacAddress SERVER_IFACE_MAC = MacAddress.valueOf("00:00:00:00:00:01");
Yi Tseng4025a102017-09-30 11:35:42 +0800230 private static final Interface SERVER_INTERFACE = createInterface("SERVER",
231 SERVER_CONNECT_POINT,
232 INTERFACE_IPS,
233 SERVER_IFACE_MAC,
234 SERVER_VLAN,
235 SERVER_VLAN_NATIVE);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700236
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700237 // Relay agent config
238 private static final Ip4Address RELAY_AGENT_IP = Ip4Address.valueOf("10.0.4.254");
239
Yi Tseng525ff402017-10-23 19:39:39 -0700240 private static final List<TrafficSelector> DHCP_SELECTORS = buildClientDhcpSelectors();
241
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700242 // Components
243 private static final ApplicationId APP_ID = TestApplicationId.create(DhcpRelayManager.DHCP_RELAY_APP);
Yi Tseng483ac6f2017-08-02 15:03:31 -0700244 private static final DefaultDhcpRelayConfig CONFIG = new MockDefaultDhcpRelayConfig();
Kalhee Kim45fede42017-09-05 19:05:06 +0000245 private static final IndirectDhcpRelayConfig CONFIG_INDIRECT = new MockIndirectDhcpRelayConfig();
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700246 private static final Set<Interface> INTERFACES = ImmutableSet.of(
247 CLIENT_INTERFACE,
248 CLIENT2_INTERFACE,
Yi Tsengaa417a62017-09-08 17:22:51 -0700249 SERVER_INTERFACE,
250 CLIENT_DH_INTERFACE
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700251 );
Yi Tseng440e2b72017-08-24 14:47:34 -0700252 private static final String NON_ONOS_CID = "Non-ONOS circuit ID";
Yi Tseng51f1be92017-09-01 17:24:57 -0700253 private static final VlanId IGNORED_VLAN = VlanId.vlanId("100");
254 private static final int IGNORE_CONTROL_PRIORITY = PacketPriority.CONTROL.priorityValue() + 1000;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700255
256 private DhcpRelayManager manager;
257 private MockPacketService packetService;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700258 private MockRouteStore mockRouteStore;
259 private MockDhcpRelayStore mockDhcpRelayStore;
Kalhee Kimd94ceea2017-11-29 19:03:02 +0000260 private MockDhcpRelayCountersStore mockDhcpRelayCountersStore;
Yi Tsengaa417a62017-09-08 17:22:51 -0700261 private HostProviderService mockHostProviderService;
Yi Tseng525ff402017-10-23 19:39:39 -0700262 private FlowObjectiveService flowObjectiveService;
263 private DeviceService deviceService;
264 private Dhcp4HandlerImpl v4Handler;
265 private Dhcp6HandlerImpl v6Handler;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700266
Yi Tseng4025a102017-09-30 11:35:42 +0800267 private static Interface createInterface(String name, ConnectPoint connectPoint,
268 List<InterfaceIpAddress> interfaceIps,
269 MacAddress macAddress,
270 VlanId vlanId,
271 VlanId vlanNative) {
272
273 if (vlanId.equals(VlanId.NONE)) {
274 return new Interface(name, connectPoint, interfaceIps, macAddress, vlanId,
275 null, null, vlanNative);
276 } else {
277 return new Interface(name, connectPoint, interfaceIps, macAddress, vlanId,
278 null, ImmutableSet.of(vlanId), null);
279 }
280 }
281
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700282 @Before
283 public void setup() {
284 manager = new DhcpRelayManager();
285 manager.cfgService = createNiceMock(NetworkConfigRegistry.class);
286
Yi Tseng483ac6f2017-08-02 15:03:31 -0700287 expect(manager.cfgService.getConfig(APP_ID, DefaultDhcpRelayConfig.class))
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700288 .andReturn(CONFIG)
289 .anyTimes();
290
Yi Tseng483ac6f2017-08-02 15:03:31 -0700291 expect(manager.cfgService.getConfig(APP_ID, IndirectDhcpRelayConfig.class))
Kalhee Kim45fede42017-09-05 19:05:06 +0000292 .andReturn(CONFIG_INDIRECT)
Yi Tseng483ac6f2017-08-02 15:03:31 -0700293 .anyTimes();
294
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700295 manager.coreService = createNiceMock(CoreService.class);
296 expect(manager.coreService.registerApplication(anyString()))
297 .andReturn(APP_ID).anyTimes();
298
299 manager.hostService = createNiceMock(HostService.class);
Kalhee Kim121ba922017-11-01 17:56:44 +0000300
301 expect(manager.hostService.getHostsByIp(OUTER_RELAY_IP_V6))
302 .andReturn(ImmutableSet.of(OUTER_RELAY_HOST)).anyTimes();
303 expect(manager.hostService.getHostsByIp(SERVER_IP))
304 .andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
305 expect(manager.hostService.getHostsByIp(SERVER_IP_V6))
306 .andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
307 expect(manager.hostService.getHostsByIp(GATEWAY_IP))
308 .andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
309 expect(manager.hostService.getHostsByIp(GATEWAY_IP_V6))
310 .andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
311 expect(manager.hostService.getHostsByIp(CLIENT_LL_IP_V6))
312 .andReturn(ImmutableSet.of(EXISTS_HOST)).anyTimes();
313
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700314 expect(manager.hostService.getHost(OUTER_RELAY_HOST_ID)).andReturn(OUTER_RELAY_HOST).anyTimes();
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700315
316 packetService = new MockPacketService();
317 manager.packetService = packetService;
318 manager.compCfgService = createNiceMock(ComponentConfigService.class);
Yi Tseng525ff402017-10-23 19:39:39 -0700319 deviceService = createNiceMock(DeviceService.class);
Yi Tseng127ffe52017-09-12 15:55:17 -0700320
321 Device device = createNiceMock(Device.class);
322 expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
323
Yi Tseng525ff402017-10-23 19:39:39 -0700324 expect(deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
325 expect(deviceService.getDevice(DEV_2_ID)).andReturn(device).anyTimes();
326 replay(deviceService, device);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700327
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700328 mockRouteStore = new MockRouteStore();
329 mockDhcpRelayStore = new MockDhcpRelayStore();
Kalhee Kimd94ceea2017-11-29 19:03:02 +0000330 mockDhcpRelayCountersStore = new MockDhcpRelayCountersStore();
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700331
Kalhee Kimd94ceea2017-11-29 19:03:02 +0000332 manager.dhcpRelayStore = mockDhcpRelayStore;
333
334 manager.deviceService = deviceService;
Kalhee Kimba366062017-11-07 16:32:09 +0000335
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700336 manager.interfaceService = new MockInterfaceService();
Yi Tseng525ff402017-10-23 19:39:39 -0700337 flowObjectiveService = EasyMock.niceMock(FlowObjectiveService.class);
Yi Tsengaa417a62017-09-08 17:22:51 -0700338 mockHostProviderService = createNiceMock(HostProviderService.class);
Yi Tseng525ff402017-10-23 19:39:39 -0700339 v4Handler = new Dhcp4HandlerImpl();
Yi Tsengaa417a62017-09-08 17:22:51 -0700340 v4Handler.providerService = mockHostProviderService;
Yi Tseng51301292017-07-28 13:02:59 -0700341 v4Handler.dhcpRelayStore = mockDhcpRelayStore;
342 v4Handler.hostService = manager.hostService;
Yi Tseng51301292017-07-28 13:02:59 -0700343 v4Handler.interfaceService = manager.interfaceService;
344 v4Handler.packetService = manager.packetService;
345 v4Handler.routeStore = mockRouteStore;
Yi Tseng525ff402017-10-23 19:39:39 -0700346 v4Handler.coreService = createNiceMock(CoreService.class);
347 v4Handler.flowObjectiveService = flowObjectiveService;
348 v4Handler.appId = TestApplicationId.create(Dhcp4HandlerImpl.DHCP_V4_RELAY_APP);
349 v4Handler.deviceService = deviceService;
Yi Tseng51301292017-07-28 13:02:59 -0700350 manager.v4Handler = v4Handler;
351
Yi Tseng525ff402017-10-23 19:39:39 -0700352 v6Handler = new Dhcp6HandlerImpl();
Kalhee Kim45fede42017-09-05 19:05:06 +0000353 v6Handler.dhcpRelayStore = mockDhcpRelayStore;
Kalhee Kimd94ceea2017-11-29 19:03:02 +0000354 v6Handler.dhcpRelayCountersStore = mockDhcpRelayCountersStore;
Kalhee Kim45fede42017-09-05 19:05:06 +0000355 v6Handler.hostService = manager.hostService;
Kalhee Kim45fede42017-09-05 19:05:06 +0000356 v6Handler.interfaceService = manager.interfaceService;
357 v6Handler.packetService = manager.packetService;
358 v6Handler.routeStore = mockRouteStore;
Yi Tsengaa417a62017-09-08 17:22:51 -0700359 v6Handler.providerService = mockHostProviderService;
Yi Tseng525ff402017-10-23 19:39:39 -0700360 v6Handler.coreService = createNiceMock(CoreService.class);
361 v6Handler.flowObjectiveService = flowObjectiveService;
362 v6Handler.appId = TestApplicationId.create(Dhcp6HandlerImpl.DHCP_V6_RELAY_APP);
363 v6Handler.deviceService = deviceService;
Yi Tseng483ac6f2017-08-02 15:03:31 -0700364 manager.v6Handler = v6Handler;
365
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700366 // properties
367 Dictionary<String, Object> dictionary = createNiceMock(Dictionary.class);
368 expect(dictionary.get("arpEnabled")).andReturn(true).anyTimes();
Kalhee Kim495c9b22017-11-07 16:32:09 +0000369 expect(dictionary.get("dhcpPollInterval")).andReturn(120).anyTimes();
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700370 ComponentContext context = createNiceMock(ComponentContext.class);
371 expect(context.getProperties()).andReturn(dictionary).anyTimes();
372
Yi Tseng4025a102017-09-30 11:35:42 +0800373 replay(manager.cfgService, manager.coreService, manager.hostService,
374 manager.compCfgService, dictionary, context);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700375 manager.activate(context);
376 }
377
378 @After
379 public void tearDown() {
380 manager.deactivate();
381 }
382
383 /**
384 * Relay a DHCP packet without option 82.
385 * Should add new host to host store after dhcp ack.
386 */
387 @Test
388 public void relayDhcpWithoutAgentInfo() {
Yi Tsengaa417a62017-09-08 17:22:51 -0700389 replay(mockHostProviderService);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700390 // send request
391 packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT_MAC,
392 CLIENT_VLAN,
393 CLIENT_CP,
394 INTERFACE_IP.ipAddress().getIp4Address(),
395 false));
Yi Tsengaa417a62017-09-08 17:22:51 -0700396 // won't trigger the host provider service
397 verify(mockHostProviderService);
398 reset(mockHostProviderService);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700399
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700400 assertEquals(0, mockRouteStore.routes.size());
401
Yi Tsengaa417a62017-09-08 17:22:51 -0700402 HostId expectHostId = HostId.hostId(CLIENT_MAC, CLIENT_VLAN);
403 Capture<HostDescription> capturedHostDesc = newCapture();
404 mockHostProviderService.hostDetected(eq(expectHostId), capture(capturedHostDesc), eq(false));
405 replay(mockHostProviderService);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700406 // send ack
407 packetService.processPacket(new TestDhcpAckPacketContext(CLIENT_CP, CLIENT_MAC,
408 CLIENT_VLAN, INTERFACE_IP.ipAddress().getIp4Address(),
409 false));
Yi Tsengaa417a62017-09-08 17:22:51 -0700410 verify(mockHostProviderService);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700411 assertEquals(0, mockRouteStore.routes.size());
412
Yi Tsengaa417a62017-09-08 17:22:51 -0700413 HostDescription host = capturedHostDesc.getValue();
414 assertEquals(false, host.configured());
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700415 assertEquals(CLIENT_CP.deviceId(), host.location().elementId());
416 assertEquals(CLIENT_CP.port(), host.location().port());
Yi Tsengaa417a62017-09-08 17:22:51 -0700417 assertEquals(1, host.ipAddress().size());
418 assertEquals(IP_FOR_CLIENT, host.ipAddress().iterator().next());
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700419 }
420
421 /**
422 * Relay a DHCP packet with option 82 (Indirectly connected host).
423 */
424 @Test
425 public void relayDhcpWithAgentInfo() {
Yi Tsengaa417a62017-09-08 17:22:51 -0700426 replay(mockHostProviderService);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700427 // Assume outer dhcp relay agent exists in store already
428 // send request
429 packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC,
430 CLIENT2_VLAN,
431 CLIENT2_CP,
432 INTERFACE_IP.ipAddress().getIp4Address(),
433 true));
Yi Tsengaa417a62017-09-08 17:22:51 -0700434 // No routes
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700435 assertEquals(0, mockRouteStore.routes.size());
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700436 // send ack
437 packetService.processPacket(new TestDhcpAckPacketContext(CLIENT2_CP,
438 CLIENT2_MAC,
439 CLIENT2_VLAN,
440 INTERFACE_IP.ipAddress().getIp4Address(),
441 true));
442
Yi Tsengaa417a62017-09-08 17:22:51 -0700443 // won't trigger the host provider service
444 verify(mockHostProviderService);
445 reset(mockHostProviderService);
446
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700447 assertEquals(1, mockRouteStore.routes.size());
448
449 Route route = mockRouteStore.routes.get(0);
450 assertEquals(OUTER_RELAY_IP, route.nextHop());
451 assertEquals(IP_FOR_CLIENT.toIpPrefix(), route.prefix());
Charles Chan6305b692018-04-04 11:43:54 -0700452 assertEquals(Route.Source.DHCP, route.source());
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700453 }
454
455 @Test
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700456 public void testWithRelayAgentConfig() throws DeserializationException {
457 manager.v4Handler
458 .setDefaultDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP)));
Yi Tseng4f2a0462017-08-31 11:21:00 -0700459 manager.v4Handler
460 .setIndirectDhcpServerConfigs(ImmutableList.of(new MockDhcpServerConfig(RELAY_AGENT_IP)));
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700461 packetService.processPacket(new TestDhcpRequestPacketContext(CLIENT2_MAC,
462 CLIENT2_VLAN,
463 CLIENT2_CP,
464 INTERFACE_IP.ipAddress().getIp4Address(),
465 true));
466 OutboundPacket outPacket = packetService.emittedPacket;
467 byte[] outData = outPacket.data().array();
468 Ethernet eth = Ethernet.deserializer().deserialize(outData, 0, outData.length);
469 IPv4 ip = (IPv4) eth.getPayload();
470 UDP udp = (UDP) ip.getPayload();
471 DHCP dhcp = (DHCP) udp.getPayload();
472 assertEquals(RELAY_AGENT_IP.toInt(), dhcp.getGatewayIPAddress());
473 }
474
475 @Test
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700476 public void testArpRequest() throws Exception {
477 packetService.processPacket(new TestArpRequestPacketContext(CLIENT_INTERFACE));
Ray Milkeyc108a6b2017-08-23 15:23:50 -0700478 OutboundPacket outboundPacket = packetService.emittedPacket;
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700479 byte[] outPacketData = outboundPacket.data().array();
480 Ethernet eth = Ethernet.deserializer().deserialize(outPacketData, 0, outPacketData.length);
481
482 assertEquals(eth.getEtherType(), Ethernet.TYPE_ARP);
483 ARP arp = (ARP) eth.getPayload();
484 assertArrayEquals(arp.getSenderHardwareAddress(), CLIENT_INTERFACE.mac().toBytes());
485 }
486
Yi Tseng51f1be92017-09-01 17:24:57 -0700487 /**
488 * Ignores specific vlans from specific devices if config.
489 *
490 * @throws Exception the exception from this test
491 */
492 @Test
493 public void testIgnoreVlan() throws Exception {
494 ObjectMapper om = new ObjectMapper();
495 JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
496 IgnoreDhcpConfig config = new IgnoreDhcpConfig();
497 json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
498 config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
499
500 Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
Yi Tseng525ff402017-10-23 19:39:39 -0700501 flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
Yi Tseng127ffe52017-09-12 15:55:17 -0700502 expectLastCall().times(DHCP_SELECTORS.size());
Yi Tseng51f1be92017-09-01 17:24:57 -0700503 Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
Yi Tseng525ff402017-10-23 19:39:39 -0700504 flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
Yi Tseng127ffe52017-09-12 15:55:17 -0700505 expectLastCall().times(DHCP_SELECTORS.size());
Yi Tseng525ff402017-10-23 19:39:39 -0700506 replay(flowObjectiveService);
Yi Tseng51f1be92017-09-01 17:24:57 -0700507 manager.updateConfig(config);
Yi Tseng525ff402017-10-23 19:39:39 -0700508 verify(flowObjectiveService);
Yi Tseng51f1be92017-09-01 17:24:57 -0700509
510 List<Objective> objectivesFromDev1 = capturedFromDev1.getValues();
511 List<Objective> objectivesFromDev2 = capturedFromDev2.getValues();
512
513 assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2));
514 assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1));
Yi Tseng51f1be92017-09-01 17:24:57 -0700515
516 for (int index = 0; index < objectivesFromDev1.size(); index++) {
517 TrafficSelector selector =
Yi Tseng525ff402017-10-23 19:39:39 -0700518 DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index))
Yi Tseng51f1be92017-09-01 17:24:57 -0700519 .matchVlanId(IGNORED_VLAN)
520 .build();
521 ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index);
522 assertEquals(selector, fwd.selector());
Yi Tsengdbabeed2017-11-29 10:49:20 -0800523 assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment());
Yi Tseng51f1be92017-09-01 17:24:57 -0700524 assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
525 assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
526 assertEquals(Objective.Operation.ADD, fwd.op());
Yi Tseng127ffe52017-09-12 15:55:17 -0700527 fwd.context().ifPresent(ctx -> {
528 ctx.onSuccess(fwd);
529 });
Yi Tseng51f1be92017-09-01 17:24:57 -0700530 }
Yi Tseng127ffe52017-09-12 15:55:17 -0700531 objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
Yi Tseng525ff402017-10-23 19:39:39 -0700532 assertEquals(2, v4Handler.ignoredVlans.size());
533 assertEquals(2, v6Handler.ignoredVlans.size());
Yi Tseng51f1be92017-09-01 17:24:57 -0700534 }
535
536 /**
537 * "IgnoreVlan" policy should be removed when the config removed.
538 */
539 @Test
540 public void testRemoveIgnoreVlan() {
Yi Tseng525ff402017-10-23 19:39:39 -0700541 v4Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
542 v4Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
543 v6Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
544 v6Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
Yi Tseng51f1be92017-09-01 17:24:57 -0700545 IgnoreDhcpConfig config = new IgnoreDhcpConfig();
546
547 Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
Yi Tseng525ff402017-10-23 19:39:39 -0700548 flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
Yi Tseng127ffe52017-09-12 15:55:17 -0700549 expectLastCall().times(DHCP_SELECTORS.size());
Yi Tseng51f1be92017-09-01 17:24:57 -0700550 Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
Yi Tseng525ff402017-10-23 19:39:39 -0700551 flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
Yi Tseng127ffe52017-09-12 15:55:17 -0700552 expectLastCall().times(DHCP_SELECTORS.size());
Yi Tseng525ff402017-10-23 19:39:39 -0700553 replay(flowObjectiveService);
Yi Tseng51f1be92017-09-01 17:24:57 -0700554 manager.removeConfig(config);
Yi Tseng525ff402017-10-23 19:39:39 -0700555 verify(flowObjectiveService);
Yi Tseng51f1be92017-09-01 17:24:57 -0700556
557 List<Objective> objectivesFromDev1 = capturedFromDev1.getValues();
558 List<Objective> objectivesFromDev2 = capturedFromDev2.getValues();
559
560 assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2));
561 assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1));
Yi Tseng51f1be92017-09-01 17:24:57 -0700562
563 for (int index = 0; index < objectivesFromDev1.size(); index++) {
564 TrafficSelector selector =
Yi Tseng525ff402017-10-23 19:39:39 -0700565 DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index))
Yi Tseng51f1be92017-09-01 17:24:57 -0700566 .matchVlanId(IGNORED_VLAN)
567 .build();
568 ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index);
569 assertEquals(selector, fwd.selector());
Yi Tsengdbabeed2017-11-29 10:49:20 -0800570 assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment());
Yi Tseng51f1be92017-09-01 17:24:57 -0700571 assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
572 assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
573 assertEquals(Objective.Operation.REMOVE, fwd.op());
Yi Tseng127ffe52017-09-12 15:55:17 -0700574 fwd.context().ifPresent(ctx -> {
575 ctx.onSuccess(fwd);
576 });
Yi Tseng51f1be92017-09-01 17:24:57 -0700577 }
Yi Tseng127ffe52017-09-12 15:55:17 -0700578 objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
Yi Tseng525ff402017-10-23 19:39:39 -0700579 assertEquals(0, v4Handler.ignoredVlans.size());
580 assertEquals(0, v6Handler.ignoredVlans.size());
Yi Tseng51f1be92017-09-01 17:24:57 -0700581 }
582
Kalhee Kim45fede42017-09-05 19:05:06 +0000583 /**
Yi Tseng127ffe52017-09-12 15:55:17 -0700584 * Should ignore ignore rules installation when device not available.
585 */
586 @Test
587 public void testIgnoreUnknownDevice() throws IOException {
588 reset(manager.deviceService);
589 Device device = createNiceMock(Device.class);
590 expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
591
592 expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
593 expect(manager.deviceService.getDevice(DEV_2_ID)).andReturn(null).anyTimes();
594
595 ObjectMapper om = new ObjectMapper();
596 JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
597 IgnoreDhcpConfig config = new IgnoreDhcpConfig();
598 json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
599 config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
600
601 Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
Yi Tseng525ff402017-10-23 19:39:39 -0700602 flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
Yi Tseng127ffe52017-09-12 15:55:17 -0700603 expectLastCall().times(DHCP_SELECTORS.size());
Yi Tseng525ff402017-10-23 19:39:39 -0700604 replay(flowObjectiveService, manager.deviceService, device);
Yi Tseng127ffe52017-09-12 15:55:17 -0700605
606 manager.updateConfig(config);
607 capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
608
Yi Tseng525ff402017-10-23 19:39:39 -0700609 assertEquals(1, v4Handler.ignoredVlans.size());
610 assertEquals(1, v6Handler.ignoredVlans.size());
Yi Tseng127ffe52017-09-12 15:55:17 -0700611 }
612
613 /**
614 * Should try install ignore rules when device comes up.
615 */
616 @Test
617 public void testInstallIgnoreRuleWhenDeviceComesUp() throws IOException {
618 ObjectMapper om = new ObjectMapper();
619 JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
620 IgnoreDhcpConfig config = new IgnoreDhcpConfig();
621 json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
622 config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
623
Yi Tseng525ff402017-10-23 19:39:39 -0700624 reset(manager.cfgService, flowObjectiveService, manager.deviceService);
Yi Tseng127ffe52017-09-12 15:55:17 -0700625 expect(manager.cfgService.getConfig(APP_ID, IgnoreDhcpConfig.class))
626 .andReturn(config).anyTimes();
627
628 Device device = createNiceMock(Device.class);
629 expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
630 expect(device.id()).andReturn(DEV_1_ID).anyTimes();
631 expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
632 DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
633 Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
Yi Tseng525ff402017-10-23 19:39:39 -0700634 flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
Yi Tseng127ffe52017-09-12 15:55:17 -0700635 expectLastCall().times(DHCP_SELECTORS.size());
Yi Tseng525ff402017-10-23 19:39:39 -0700636 replay(manager.cfgService, flowObjectiveService, manager.deviceService, device);
Yi Tseng127ffe52017-09-12 15:55:17 -0700637 manager.deviceListener.event(event);
638 capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
Yi Tseng525ff402017-10-23 19:39:39 -0700639 assertEquals(1, v4Handler.ignoredVlans.size());
640 assertEquals(1, v6Handler.ignoredVlans.size());
Yi Tseng127ffe52017-09-12 15:55:17 -0700641 }
642
643 /**
Kalhee Kim45fede42017-09-05 19:05:06 +0000644 * Relay a DHCP6 packet without relay option
645 * Note: Should add new host to host store after dhcp ack.
646 */
647 @Test
648 public void relayDhcp6WithoutAgentInfo() {
Yi Tsengaa417a62017-09-08 17:22:51 -0700649 replay(mockHostProviderService);
Kalhee Kim45fede42017-09-05 19:05:06 +0000650 // send request
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000651 packetService.processPacket(new TestDhcp6RequestPacketContext(DHCP6.MsgType.REQUEST.value(),
652 CLIENT_MAC,
653 CLIENT_VLAN,
Kalhee Kim45fede42017-09-05 19:05:06 +0000654 CLIENT_CP,
655 INTERFACE_IP_V6.ipAddress().getIp6Address(),
656 0));
657
Yi Tsengaa417a62017-09-08 17:22:51 -0700658 verify(mockHostProviderService);
659 reset(mockHostProviderService);
Kalhee Kim45fede42017-09-05 19:05:06 +0000660 assertEquals(0, mockRouteStore.routes.size());
661
Yi Tsengaa417a62017-09-08 17:22:51 -0700662 Capture<HostDescription> capturedHostDesc = newCapture();
663 mockHostProviderService.hostDetected(eq(HostId.hostId(CLIENT_MAC, CLIENT_VLAN)),
664 capture(capturedHostDesc), eq(false));
665 replay(mockHostProviderService);
Kalhee Kim45fede42017-09-05 19:05:06 +0000666 // send reply
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000667 packetService.processPacket(new TestDhcp6ReplyPacketContext(DHCP6.MsgType.REPLY.value(),
668 CLIENT_CP, CLIENT_MAC,
Kalhee Kim45fede42017-09-05 19:05:06 +0000669 CLIENT_VLAN,
670 INTERFACE_IP_V6.ipAddress().getIp6Address(),
Kalhee Kim121ba922017-11-01 17:56:44 +0000671 0, false, CLIENT_VLAN));
Yi Tsengaa417a62017-09-08 17:22:51 -0700672 verify(mockHostProviderService);
Kalhee Kim45fede42017-09-05 19:05:06 +0000673 assertEquals(0, mockRouteStore.routes.size());
674
Yi Tsengaa417a62017-09-08 17:22:51 -0700675 HostDescription host = capturedHostDesc.getValue();
Kalhee Kim45fede42017-09-05 19:05:06 +0000676 assertEquals(CLIENT_VLAN, host.vlan());
677 assertEquals(CLIENT_CP.deviceId(), host.location().elementId());
678 assertEquals(CLIENT_CP.port(), host.location().port());
Yi Tsengaa417a62017-09-08 17:22:51 -0700679 assertEquals(1, host.ipAddress().size());
680 assertEquals(IP_FOR_CLIENT_V6, host.ipAddress().iterator().next());
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000681
682 // send release
683 packetService.processPacket(new TestDhcp6RequestPacketContext(DHCP6.MsgType.RELEASE.value(),
684 CLIENT_MAC,
685 CLIENT_VLAN,
686 CLIENT_CP,
687 INTERFACE_IP_V6.ipAddress().getIp6Address(),
688 0));
689
690 assertEquals(null, manager.hostService.getHost(HostId.hostId(CLIENT_MAC, CLIENT_VLAN)));
Kalhee Kim45fede42017-09-05 19:05:06 +0000691 }
692
693 /**
694 * Relay a DHCP6 packet with Relay Message opion (Indirectly connected host).
695 */
696 @Test
697 public void relayDhcp6WithAgentInfo() {
Yi Tsengaa417a62017-09-08 17:22:51 -0700698 replay(mockHostProviderService);
Kalhee Kim45fede42017-09-05 19:05:06 +0000699 // Assume outer dhcp6 relay agent exists in store already
700 // send request
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000701 packetService.processPacket(new TestDhcp6RequestPacketContext(DHCP6.MsgType.REQUEST.value(),
702 CLIENT2_MAC,
703 CLIENT2_VLAN,
704 CLIENT2_CP,
705 OUTER_RELAY_IP_V6,
706 1));
707
708 assertEquals(0, mockRouteStore.routes.size());
709
710 // send reply
711 packetService.processPacket(new TestDhcp6ReplyPacketContext(DHCP6.MsgType.REPLY.value(), CLIENT2_CP,
712 CLIENT2_MAC,
713 CLIENT2_VLAN,
714 OUTER_RELAY_IP_V6,
Kalhee Kim121ba922017-11-01 17:56:44 +0000715 1, false, CLIENT2_VLAN));
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000716
717 // won't trigger the host provider service
718 verify(mockHostProviderService);
719 reset(mockHostProviderService);
720 assertEquals(2, mockRouteStore.routes.size()); // ipAddress and prefix
721
722 Route aRoute = mockRouteStore.routes.stream()
723 .filter(rt -> rt.prefix().contains(IP_FOR_CLIENT_V6))
724 .findFirst()
725 .orElse(null);
726 assertNotEquals(null, aRoute);
727
728 aRoute = mockRouteStore.routes.stream()
729 .filter(rt -> rt.prefix().contains(PREFIX_FOR_CLIENT_V6))
730 .findFirst()
731 .orElse(null);
732 assertNotEquals(null, aRoute);
733
734 // send release msg
735 packetService.processPacket(new TestDhcp6RequestPacketContext(DHCP6.MsgType.RELEASE.value(),
736 CLIENT2_MAC,
737 CLIENT2_VLAN,
738 CLIENT2_CP,
739 OUTER_RELAY_IP_V6,
740 1));
741
742 aRoute = mockRouteStore.routes.stream()
743 .filter(rt -> rt.prefix().contains(IP_FOR_CLIENT_V6))
744 .findFirst()
745 .orElse(null);
746 assertEquals(null, aRoute);
747
748 aRoute = mockRouteStore.routes.stream()
749 .filter(rt -> rt.prefix().contains(PREFIX_FOR_CLIENT_V6))
750 .findFirst()
751 .orElse(null);
752 assertEquals(null, aRoute);
753
754 assertEquals(0, mockRouteStore.routes.size());
755
756 }
757
758 /**
759 * Relay a DHCP6 packet with Relay Message opion (Indirectly connected host) and server responded
760 * with vlan differnt from client interface vlan.
761 */
762 @Test
763 public void relayDhcp6WithAgentInfoWrongVlan() {
764 replay(mockHostProviderService);
765 // Assume outer dhcp6 relay agent exists in store already
766 // send request
767 packetService.processPacket(new TestDhcp6RequestPacketContext(DHCP6.MsgType.REQUEST.value(),
768 CLIENT2_MAC,
Kalhee Kim45fede42017-09-05 19:05:06 +0000769 CLIENT2_VLAN,
770 CLIENT2_CP,
771 INTERFACE_IP_V6.ipAddress().getIp6Address(),
772 1));
773
Kalhee Kim45fede42017-09-05 19:05:06 +0000774 assertEquals(0, mockRouteStore.routes.size());
775
776 // send reply
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000777 packetService.processPacket(new TestDhcp6ReplyPacketContext(DHCP6.MsgType.REPLY.value(),
778 CLIENT2_CP,
Kalhee Kim45fede42017-09-05 19:05:06 +0000779 CLIENT2_MAC,
Kalhee Kim121ba922017-11-01 17:56:44 +0000780 CLIENT2_VLAN,
Kalhee Kim45fede42017-09-05 19:05:06 +0000781 INTERFACE_IP_V6.ipAddress().getIp6Address(),
Kalhee Kim121ba922017-11-01 17:56:44 +0000782 1, true,
783 CLIENT_BOGUS_VLAN // mismatch
784 ));
Kalhee Kim45fede42017-09-05 19:05:06 +0000785
Yi Tsengaa417a62017-09-08 17:22:51 -0700786 // won't trigger the host provider service
787 verify(mockHostProviderService);
788 reset(mockHostProviderService);
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000789 assertEquals(0, mockRouteStore.routes.size()); // ipAddress and prefix
Kalhee Kim45fede42017-09-05 19:05:06 +0000790
Kalhee Kim45fede42017-09-05 19:05:06 +0000791 }
Yi Tsengaa417a62017-09-08 17:22:51 -0700792
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000793
Yi Tsengaa417a62017-09-08 17:22:51 -0700794 @Test
795 public void testDhcp4DualHome() {
796 PacketContext packetContext =
797 new TestDhcpAckPacketContext(CLIENT_DH_CP, CLIENT_MAC, CLIENT_VLAN,
798 INTERFACE_IP.ipAddress().getIp4Address(),
799 false);
800 reset(manager.hostService);
801 expect(manager.hostService.getHost(CLIENT_HOST_ID)).andReturn(EXISTS_HOST).anyTimes();
802 Capture<HostDescription> capturedHostDesc = newCapture();
803 mockHostProviderService.hostDetected(eq(CLIENT_HOST_ID), capture(capturedHostDesc), eq(false));
804 replay(mockHostProviderService, manager.hostService);
805 packetService.processPacket(packetContext);
806 verify(mockHostProviderService);
807
808 HostDescription hostDesc = capturedHostDesc.getValue();
809 Set<HostLocation> hostLocations = hostDesc.locations();
810 assertEquals(2, hostLocations.size());
811 assertTrue(hostLocations.contains(CLIENT_LOCATION));
812 assertTrue(hostLocations.contains(CLIENT_DH_LOCATION));
813 }
814
815 @Test
816 public void testDhcp6DualHome() {
817 PacketContext packetContext =
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000818 new TestDhcp6ReplyPacketContext(DHCP6.MsgType.REPLY.value(),
819 CLIENT_DH_CP, CLIENT_MAC, CLIENT_VLAN,
Yi Tsengaa417a62017-09-08 17:22:51 -0700820 INTERFACE_IP_V6.ipAddress().getIp6Address(),
Kalhee Kim121ba922017-11-01 17:56:44 +0000821 0, false, CLIENT_VLAN);
Yi Tsengaa417a62017-09-08 17:22:51 -0700822 reset(manager.hostService);
823 expect(manager.hostService.getHostsByIp(CLIENT_LL_IP_V6)).andReturn(ImmutableSet.of(EXISTS_HOST)).anyTimes();
824
825 // FIXME: currently DHCPv6 has a bug, we can't get correct vlan of client......
826 // XXX: The vlan relied from DHCP6 handler might be wrong, do hack here
827 HostId hostId = HostId.hostId(CLIENT_MAC, VlanId.NONE);
828 expect(manager.hostService.getHost(hostId)).andReturn(EXISTS_HOST).anyTimes();
829
830 // XXX: sometimes this will work, sometimes not
831 expect(manager.hostService.getHost(CLIENT_HOST_ID)).andReturn(EXISTS_HOST).anyTimes();
832
833 Capture<HostDescription> capturedHostDesc = newCapture();
834
835 // XXX: also a hack here
836 mockHostProviderService.hostDetected(eq(hostId), capture(capturedHostDesc), eq(false));
837 expectLastCall().anyTimes();
838
839 mockHostProviderService.hostDetected(eq(CLIENT_HOST_ID), capture(capturedHostDesc), eq(false));
840 expectLastCall().anyTimes();
841 replay(mockHostProviderService, manager.hostService);
842 packetService.processPacket(packetContext);
843 verify(mockHostProviderService);
844
845 HostDescription hostDesc = capturedHostDesc.getValue();
846 Set<HostLocation> hostLocations = hostDesc.locations();
847 assertEquals(2, hostLocations.size());
848 assertTrue(hostLocations.contains(CLIENT_LOCATION));
849 assertTrue(hostLocations.contains(CLIENT_DH_LOCATION));
850 }
851
Yi Tseng483ac6f2017-08-02 15:03:31 -0700852 private static class MockDefaultDhcpRelayConfig extends DefaultDhcpRelayConfig {
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700853 @Override
854 public boolean isValid() {
855 return true;
856 }
857
858 @Override
Yi Tseng483ac6f2017-08-02 15:03:31 -0700859 public List<DhcpServerConfig> dhcpServerConfigs() {
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700860 return ImmutableList.of(new MockDhcpServerConfig(null));
Yi Tseng483ac6f2017-08-02 15:03:31 -0700861 }
862 }
863
Kalhee Kim45fede42017-09-05 19:05:06 +0000864 private static class MockIndirectDhcpRelayConfig extends IndirectDhcpRelayConfig {
865 @Override
866 public boolean isValid() {
867 return true;
868 }
869
870 @Override
871 public List<DhcpServerConfig> dhcpServerConfigs() {
872 return ImmutableList.of(new MockDhcpServerConfig(null));
873 }
874 }
875
Yi Tseng483ac6f2017-08-02 15:03:31 -0700876 private static class MockDhcpServerConfig extends DhcpServerConfig {
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700877 Ip4Address relayAgentIp;
878
879 /**
880 * Create mocked version DHCP server config.
881 *
882 * @param relayAgentIp the relay agent Ip config; null if we don't need it
883 */
884 public MockDhcpServerConfig(Ip4Address relayAgentIp) {
885 this.relayAgentIp = relayAgentIp;
Yi Tseng25bfe372017-11-03 16:27:32 -0700886 this.relayAgentIps.put(DEV_1_ID, Pair.of(relayAgentIp, null));
887 this.relayAgentIps.put(DEV_2_ID, Pair.of(relayAgentIp, null));
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700888 }
889
890 @Override
Yi Tseng25bfe372017-11-03 16:27:32 -0700891 public Optional<Ip4Address> getRelayAgentIp4(DeviceId deviceId) {
892 return Optional.ofNullable(this.relayAgentIps.get(deviceId).getLeft());
Yi Tseng3df7f9d2017-08-17 13:08:31 -0700893 }
894
Yi Tseng483ac6f2017-08-02 15:03:31 -0700895 @Override
896 public Optional<ConnectPoint> getDhcpServerConnectPoint() {
897 return Optional.of(SERVER_CONNECT_POINT);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700898 }
899
Yi Tseng483ac6f2017-08-02 15:03:31 -0700900 @Override
901 public Optional<Ip4Address> getDhcpServerIp4() {
902 return Optional.of(SERVER_IP);
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700903 }
Kalhee Kim45fede42017-09-05 19:05:06 +0000904
905 @Override
906 public Optional<Ip4Address> getDhcpGatewayIp4() {
907 return Optional.of(GATEWAY_IP);
908 }
909
910 @Override
911 public Optional<Ip6Address> getDhcpServerIp6() {
912 return Optional.of(SERVER_IP_V6);
913 }
914
915 @Override
916 public Optional<Ip6Address> getDhcpGatewayIp6() {
917 return Optional.of(GATEWAY_IP_V6);
918 }
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700919 }
920
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700921 private class MockRouteStore extends RouteStoreAdapter {
922 private List<Route> routes = Lists.newArrayList();
923
924 @Override
925 public void updateRoute(Route route) {
926 routes.add(route);
927 }
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +0000928
929 @Override
930 public void removeRoute(Route route) {
931 routes.remove(route);
932 }
Daniel Ginsburg83b76452018-06-09 01:43:59 +0300933
934 public void replaceRoute(Route route) {
935 routes.remove(route);
936 routes.add(route);
937 }
Yi Tseng7a38f9a2017-06-09 14:36:40 -0700938 }
939
940 private class MockInterfaceService extends InterfaceServiceAdapter {
941
942 @Override
943 public Set<Interface> getInterfaces() {
944 return INTERFACES;
945 }
946
947 @Override
948 public Set<Interface> getInterfacesByIp(IpAddress ip) {
949 return INTERFACES.stream()
950 .filter(iface -> {
951 return iface.ipAddressesList().stream()
952 .anyMatch(ifaceIp -> ifaceIp.ipAddress().equals(ip));
953 })
954 .collect(Collectors.toSet());
955 }
956
957 @Override
958 public Set<Interface> getInterfacesByPort(ConnectPoint port) {
959 return INTERFACES.stream()
960 .filter(iface -> iface.connectPoint().equals(port))
961 .collect(Collectors.toSet());
962 }
963 }
964
965 private class MockDhcpRelayStore implements DhcpRelayStore {
966 StoreDelegate<DhcpRelayStoreEvent> delegate;
967 private Map<HostId, DhcpRecord> records = Maps.newHashMap();
968
969 @Override
970 public void updateDhcpRecord(HostId hostId, DhcpRecord dhcpRecord) {
971 records.put(hostId, dhcpRecord);
972 DhcpRelayStoreEvent event = new DhcpRelayStoreEvent(DhcpRelayStoreEvent.Type.UPDATED,
973 dhcpRecord);
974 if (delegate != null) {
975 delegate.notify(event);
976 }
977 }
978
979 @Override
980 public Optional<DhcpRecord> getDhcpRecord(HostId hostId) {
981 return Optional.ofNullable(records.get(hostId));
982 }
983
984 @Override
985 public Collection<DhcpRecord> getDhcpRecords() {
986 return records.values();
987 }
988
989 @Override
990 public Optional<DhcpRecord> removeDhcpRecord(HostId hostId) {
991 DhcpRecord dhcpRecord = records.remove(hostId);
992 if (dhcpRecord != null) {
993 DhcpRelayStoreEvent event = new DhcpRelayStoreEvent(DhcpRelayStoreEvent.Type.REMOVED,
994 dhcpRecord);
995 if (delegate != null) {
996 delegate.notify(event);
997 }
998 }
999 return Optional.ofNullable(dhcpRecord);
1000 }
1001
1002 @Override
1003 public void setDelegate(StoreDelegate<DhcpRelayStoreEvent> delegate) {
1004 this.delegate = delegate;
1005 }
1006
1007 @Override
1008 public void unsetDelegate(StoreDelegate<DhcpRelayStoreEvent> delegate) {
1009 this.delegate = null;
1010 }
1011
1012 @Override
1013 public boolean hasDelegate() {
1014 return this.delegate != null;
1015 }
1016 }
1017
Kalhee Kimd94ceea2017-11-29 19:03:02 +00001018 private class MockDhcpRelayCountersStore implements DhcpRelayCountersStore {
1019 private Map<String, DhcpRelayCounters> counters = Maps.newHashMap();
1020
1021 public void incrementCounter(String coutnerClass, String counterName) {
1022 DhcpRelayCounters countersRecord;
1023
1024 DhcpRelayCounters classCounters = counters.get(coutnerClass);
1025 if (classCounters == null) {
1026 classCounters = new DhcpRelayCounters();
1027 }
1028 classCounters.incrementCounter(counterName);
1029 counters.put(coutnerClass, classCounters);
1030 }
1031
1032 @Override
1033 public Set<Map.Entry<String, DhcpRelayCounters>> getAllCounters() {
1034 return counters.entrySet();
1035 }
1036
1037 @Override
1038 public Optional<DhcpRelayCounters> getCounters(String counterClass) {
1039 DhcpRelayCounters classCounters = counters.get(counterClass);
1040 if (classCounters == null) {
1041 return Optional.empty();
1042 }
1043 return Optional.of(classCounters);
1044 }
1045
1046 @Override
1047 public void resetAllCounters() {
1048 counters.clear();
1049 }
1050
1051 @Override
1052 public void resetCounters(String counterClass) {
1053 DhcpRelayCounters classCounters = counters.get(counterClass);
1054 classCounters.resetCounters();
1055 counters.put(counterClass, classCounters);
1056 }
1057 }
1058
1059
Yi Tseng7a38f9a2017-06-09 14:36:40 -07001060 private class MockPacketService extends PacketServiceAdapter {
1061 Set<PacketProcessor> packetProcessors = Sets.newHashSet();
Ray Milkeyc108a6b2017-08-23 15:23:50 -07001062 OutboundPacket emittedPacket;
Yi Tseng7a38f9a2017-06-09 14:36:40 -07001063
1064 @Override
1065 public void addProcessor(PacketProcessor processor, int priority) {
1066 packetProcessors.add(processor);
1067 }
1068
1069 public void processPacket(PacketContext packetContext) {
1070 packetProcessors.forEach(p -> p.process(packetContext));
1071 }
1072
1073 @Override
1074 public void emit(OutboundPacket packet) {
Ray Milkeyc108a6b2017-08-23 15:23:50 -07001075 this.emittedPacket = packet;
Yi Tseng7a38f9a2017-06-09 14:36:40 -07001076 }
1077 }
1078
1079
1080
1081 /**
1082 * Generates DHCP REQUEST packet.
1083 */
1084 private class TestDhcpRequestPacketContext extends PacketContextAdapter {
1085
1086
1087 private InboundPacket inPacket;
1088
1089 public TestDhcpRequestPacketContext(MacAddress clientMac, VlanId vlanId,
1090 ConnectPoint clientCp,
1091 Ip4Address clientGwAddr,
1092 boolean withNonOnosRelayInfo) {
1093 super(0, null, null, false);
1094 byte[] dhcpMsgType = new byte[1];
1095 dhcpMsgType[0] = (byte) DHCP.MsgType.DHCPREQUEST.getValue();
1096
1097 DhcpOption dhcpOption = new DhcpOption();
1098 dhcpOption.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue());
1099 dhcpOption.setData(dhcpMsgType);
1100 dhcpOption.setLength((byte) 1);
1101 DhcpOption endOption = new DhcpOption();
1102 endOption.setCode(DHCP.DHCPOptionCode.OptionCode_END.getValue());
1103
1104 DHCP dhcp = new DHCP();
1105 dhcp.setHardwareType(DHCP.HWTYPE_ETHERNET);
1106 dhcp.setHardwareAddressLength((byte) 6);
1107 dhcp.setClientHardwareAddress(clientMac.toBytes());
1108 if (withNonOnosRelayInfo) {
1109 DhcpRelayAgentOption relayOption = new DhcpRelayAgentOption();
1110 DhcpOption circuitIdOption = new DhcpOption();
1111 CircuitId circuitId = new CircuitId("Custom option", VlanId.NONE);
1112 byte[] cid = circuitId.serialize();
1113 circuitIdOption.setCode(DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID.getValue());
1114 circuitIdOption.setLength((byte) cid.length);
1115 circuitIdOption.setData(cid);
1116 relayOption.setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue());
1117 relayOption.addSubOption(circuitIdOption);
1118 dhcp.setOptions(ImmutableList.of(dhcpOption, relayOption, endOption));
1119 dhcp.setGatewayIPAddress(OUTER_RELAY_IP.getIp4Address().toInt());
1120 } else {
1121 dhcp.setOptions(ImmutableList.of(dhcpOption, endOption));
1122 }
1123
1124
1125 UDP udp = new UDP();
1126 udp.setPayload(dhcp);
1127 udp.setSourcePort(UDP.DHCP_CLIENT_PORT);
1128 udp.setDestinationPort(UDP.DHCP_SERVER_PORT);
1129
1130 IPv4 ipv4 = new IPv4();
1131 ipv4.setPayload(udp);
1132 ipv4.setDestinationAddress(SERVER_IP.toInt());
1133 ipv4.setSourceAddress(clientGwAddr.toInt());
1134
1135 Ethernet eth = new Ethernet();
1136 if (withNonOnosRelayInfo) {
1137 eth.setEtherType(Ethernet.TYPE_IPV4)
1138 .setVlanID(vlanId.toShort())
1139 .setSourceMACAddress(OUTER_RELAY_MAC)
1140 .setDestinationMACAddress(MacAddress.BROADCAST)
1141 .setPayload(ipv4);
1142 } else {
1143 eth.setEtherType(Ethernet.TYPE_IPV4)
1144 .setVlanID(vlanId.toShort())
1145 .setSourceMACAddress(clientMac)
1146 .setDestinationMACAddress(MacAddress.BROADCAST)
1147 .setPayload(ipv4);
1148 }
1149
1150 this.inPacket = new DefaultInboundPacket(clientCp, eth,
1151 ByteBuffer.wrap(eth.serialize()));
1152 }
1153
1154 @Override
1155 public InboundPacket inPacket() {
1156 return this.inPacket;
1157 }
1158 }
1159
1160 /**
1161 * Generates DHCP ACK packet.
1162 */
1163 private class TestDhcpAckPacketContext extends PacketContextAdapter {
1164 private InboundPacket inPacket;
1165
1166 public TestDhcpAckPacketContext(ConnectPoint clientCp, MacAddress clientMac,
1167 VlanId clientVlan, Ip4Address clientGwAddr,
1168 boolean withNonOnosRelayInfo) {
1169 super(0, null, null, false);
1170
1171 byte[] dhcpMsgType = new byte[1];
1172 dhcpMsgType[0] = (byte) DHCP.MsgType.DHCPACK.getValue();
1173
1174 DhcpOption dhcpOption = new DhcpOption();
1175 dhcpOption.setCode(DHCP.DHCPOptionCode.OptionCode_MessageType.getValue());
1176 dhcpOption.setData(dhcpMsgType);
1177 dhcpOption.setLength((byte) 1);
1178
1179 DhcpOption endOption = new DhcpOption();
1180 endOption.setCode(DHCP.DHCPOptionCode.OptionCode_END.getValue());
1181
1182 DHCP dhcp = new DHCP();
1183 if (withNonOnosRelayInfo) {
1184 DhcpRelayAgentOption relayOption = new DhcpRelayAgentOption();
1185 DhcpOption circuitIdOption = new DhcpOption();
Yi Tseng440e2b72017-08-24 14:47:34 -07001186 String circuitId = NON_ONOS_CID;
1187 byte[] cid = circuitId.getBytes(Charsets.US_ASCII);
Yi Tseng7a38f9a2017-06-09 14:36:40 -07001188 circuitIdOption.setCode(DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID.getValue());
1189 circuitIdOption.setLength((byte) cid.length);
1190 circuitIdOption.setData(cid);
1191 relayOption.setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue());
1192 relayOption.addSubOption(circuitIdOption);
1193 dhcp.setOptions(ImmutableList.of(dhcpOption, relayOption, endOption));
1194 dhcp.setGatewayIPAddress(OUTER_RELAY_IP.getIp4Address().toInt());
1195 } else {
1196 CircuitId cid = new CircuitId(clientCp.toString(), clientVlan);
1197 byte[] circuitId = cid.serialize();
1198 DhcpOption circuitIdSubOption = new DhcpOption();
1199 circuitIdSubOption.setCode(DhcpRelayAgentOption.RelayAgentInfoOptions.CIRCUIT_ID.getValue());
1200 circuitIdSubOption.setData(circuitId);
1201 circuitIdSubOption.setLength((byte) circuitId.length);
1202
1203 DhcpRelayAgentOption relayInfoOption = new DhcpRelayAgentOption();
1204 relayInfoOption.setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue());
1205 relayInfoOption.addSubOption(circuitIdSubOption);
1206 dhcp.setOptions(ImmutableList.of(dhcpOption, relayInfoOption, endOption));
1207 dhcp.setGatewayIPAddress(clientGwAddr.toInt());
1208 }
1209 dhcp.setHardwareType(DHCP.HWTYPE_ETHERNET);
1210 dhcp.setHardwareAddressLength((byte) 6);
1211 dhcp.setClientHardwareAddress(clientMac.toBytes());
1212 dhcp.setYourIPAddress(IP_FOR_CLIENT.toInt());
1213
1214 UDP udp = new UDP();
1215 udp.setPayload(dhcp);
1216 udp.setSourcePort(UDP.DHCP_SERVER_PORT);
1217 udp.setDestinationPort(UDP.DHCP_CLIENT_PORT);
1218 IPv4 ipv4 = new IPv4();
1219 ipv4.setPayload(udp);
1220 ipv4.setDestinationAddress(IP_FOR_CLIENT.toString());
1221 ipv4.setSourceAddress(SERVER_IP.toString());
1222 Ethernet eth = new Ethernet();
1223 if (withNonOnosRelayInfo) {
1224 eth.setEtherType(Ethernet.TYPE_IPV4)
1225 .setVlanID(SERVER_VLAN.toShort())
1226 .setSourceMACAddress(SERVER_MAC)
1227 .setDestinationMACAddress(OUTER_RELAY_MAC)
1228 .setPayload(ipv4);
1229 } else {
1230 eth.setEtherType(Ethernet.TYPE_IPV4)
1231 .setVlanID(SERVER_VLAN.toShort())
1232 .setSourceMACAddress(SERVER_MAC)
1233 .setDestinationMACAddress(CLIENT_MAC)
1234 .setPayload(ipv4);
1235 }
1236
1237 this.inPacket = new DefaultInboundPacket(SERVER_CONNECT_POINT, eth,
1238 ByteBuffer.wrap(eth.serialize()));
1239
1240 }
1241
1242 @Override
1243 public InboundPacket inPacket() {
1244 return this.inPacket;
1245 }
1246 }
1247
1248 private class TestArpRequestPacketContext extends PacketContextAdapter {
1249 private InboundPacket inPacket;
1250
1251 public TestArpRequestPacketContext(Interface fromInterface) {
1252 super(0, null, null, false);
1253 ARP arp = new ARP();
1254 arp.setOpCode(ARP.OP_REQUEST);
1255
1256 IpAddress targetIp = fromInterface.ipAddressesList().get(0).ipAddress();
1257 arp.setTargetProtocolAddress(targetIp.toOctets());
1258 arp.setTargetHardwareAddress(MacAddress.BROADCAST.toBytes());
1259 arp.setSenderHardwareAddress(MacAddress.NONE.toBytes());
1260 arp.setSenderProtocolAddress(Ip4Address.valueOf(0).toOctets());
1261 arp.setHardwareAddressLength((byte) MacAddress.MAC_ADDRESS_LENGTH);
1262 Ethernet eth = new Ethernet();
1263 eth.setEtherType(Ethernet.TYPE_ARP);
1264 eth.setSourceMACAddress(MacAddress.NONE);
1265 eth.setDestinationMACAddress(MacAddress.BROADCAST);
1266 eth.setVlanID(fromInterface.vlan().toShort());
1267 eth.setPayload(arp);
1268
1269 this.inPacket = new DefaultInboundPacket(fromInterface.connectPoint(), eth,
1270 ByteBuffer.wrap(eth.serialize()));
1271 }
1272
1273 @Override
1274 public InboundPacket inPacket() {
1275 return this.inPacket;
1276 }
1277 }
Kalhee Kim45fede42017-09-05 19:05:06 +00001278
1279 /**
1280 * Generates DHCP6 REQUEST packet.
1281 */
1282 private void buildDhcp6Packet(DHCP6 dhcp6, byte msgType, Ip6Address ip6Addr, IpPrefix prefix) {
1283
1284 // build address option
1285 Dhcp6IaAddressOption iaAddressOption = new Dhcp6IaAddressOption();
1286 iaAddressOption.setCode(DHCP6.OptionCode.IAADDR.value());
1287 iaAddressOption.setIp6Address(ip6Addr);
1288 iaAddressOption.setPreferredLifetime(3600);
1289 iaAddressOption.setValidLifetime(1200);
1290 iaAddressOption.setLength((short) Dhcp6IaAddressOption.DEFAULT_LEN);
1291
Kalhee Kim495c9b22017-11-07 16:32:09 +00001292 Dhcp6ClientIdOption clientIdOption = new Dhcp6ClientIdOption();
1293 Dhcp6Duid dhcp6Duip = new Dhcp6Duid();
1294 dhcp6Duip.setDuidType(Dhcp6Duid.DuidType.DUID_LLT);
1295 dhcp6Duip.setHardwareType((short) 0x01); // Ethernet
1296 dhcp6Duip.setDuidTime(1234);
1297 dhcp6Duip.setLinkLayerAddress(CLIENT_MAC.toBytes());
1298 clientIdOption.setDuid(dhcp6Duip);
1299
Kalhee Kim45fede42017-09-05 19:05:06 +00001300 Dhcp6IaNaOption iaNaOption = new Dhcp6IaNaOption();
1301 iaNaOption.setCode(DHCP6.OptionCode.IA_NA.value());
1302 iaNaOption.setIaId(0);
1303 iaNaOption.setT1(302400);
1304 iaNaOption.setT2(483840);
1305 List<Dhcp6Option> iaNaSubOptions = new ArrayList<Dhcp6Option>();
1306 iaNaSubOptions.add(iaAddressOption);
1307 iaNaOption.setOptions(iaNaSubOptions);
1308 iaNaOption.setLength((short) (Dhcp6IaNaOption.DEFAULT_LEN + iaAddressOption.getLength()));
1309
1310 // build prefix option
1311 Dhcp6IaPrefixOption iaPrefixOption = new Dhcp6IaPrefixOption();
1312 iaPrefixOption.setCode(DHCP6.OptionCode.IAPREFIX.value());
1313 iaPrefixOption.setIp6Prefix(prefix.address().getIp6Address());
1314 iaPrefixOption.setPrefixLength((byte) prefix.prefixLength());
1315 iaPrefixOption.setPreferredLifetime(3601);
1316 iaPrefixOption.setValidLifetime(1201);
1317 iaPrefixOption.setLength((short) Dhcp6IaPrefixOption.DEFAULT_LEN);
1318
1319 Dhcp6IaPdOption iaPdOption = new Dhcp6IaPdOption();
1320 iaPdOption.setCode(DHCP6.OptionCode.IA_PD.value());
1321 iaPdOption.setIaId(0);
1322 iaPdOption.setT1(302401);
1323 iaPdOption.setT2(483841);
1324 List<Dhcp6Option> iaPdSubOptions = new ArrayList<Dhcp6Option>();
1325 iaPdSubOptions.add(iaPrefixOption);
1326 iaPdOption.setOptions(iaPdSubOptions);
1327 iaPdOption.setLength((short) (Dhcp6IaPdOption.DEFAULT_LEN + iaPrefixOption.getLength()));
1328
1329 dhcp6.setMsgType(msgType);
1330 List<Dhcp6Option> dhcp6Options = new ArrayList<Dhcp6Option>();
1331 dhcp6Options.add(iaNaOption);
Kalhee Kim495c9b22017-11-07 16:32:09 +00001332 dhcp6Options.add(clientIdOption);
Kalhee Kim45fede42017-09-05 19:05:06 +00001333 dhcp6Options.add(iaPdOption);
1334 dhcp6.setOptions(dhcp6Options);
1335
1336 }
1337
1338 private void buildRelayMsg(DHCP6 dhcp6Relay, byte msgType, Ip6Address linkAddr,
1339 Ip6Address peerAddr, byte hop, byte[] interfaceIdBytes,
1340 DHCP6 dhcp6Payload) {
1341
1342 dhcp6Relay.setMsgType(msgType);
1343
1344 dhcp6Relay.setLinkAddress(linkAddr.toOctets());
1345 dhcp6Relay.setPeerAddress(peerAddr.toOctets());
1346 dhcp6Relay.setHopCount(hop);
1347 List<Dhcp6Option> options = new ArrayList<Dhcp6Option>();
1348
1349 // interfaceId option
1350 Dhcp6Option interfaceId = new Dhcp6Option();
1351 interfaceId.setCode(DHCP6.OptionCode.INTERFACE_ID.value());
1352
1353
1354 interfaceId.setData(interfaceIdBytes);
1355 interfaceId.setLength((short) interfaceIdBytes.length);
1356 Dhcp6InterfaceIdOption interfaceIdOption = new Dhcp6InterfaceIdOption(interfaceId);
Kalhee Kima0b8f652017-10-18 22:00:30 +00001357 byte[] optionData = interfaceIdOption.getData();
Kalhee Kim45fede42017-09-05 19:05:06 +00001358 ByteBuffer bb = ByteBuffer.wrap(interfaceIdBytes);
1359
1360 byte[] macAddr = new byte[MacAddress.MAC_ADDRESS_LENGTH];
Kalhee Kima0b8f652017-10-18 22:00:30 +00001361 byte[] port = new byte[optionData.length - MacAddress.MAC_ADDRESS_LENGTH -
Kalhee Kimba366062017-11-07 16:32:09 +00001362 VLAN_LEN - SEPARATOR_LEN * 2];
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001363 short vlan;
Kalhee Kim45fede42017-09-05 19:05:06 +00001364 bb.get(macAddr);
1365 bb.get(); // separator
1366 bb.get(port);
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001367 bb.get(); // separator
1368 vlan = bb.getShort();
Kalhee Kim45fede42017-09-05 19:05:06 +00001369 interfaceIdOption.setMacAddress(MacAddress.valueOf(macAddr));
1370 interfaceIdOption.setInPort(port);
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001371 interfaceIdOption.setVlanId(vlan);
Kalhee Kim45fede42017-09-05 19:05:06 +00001372
1373 options.add(interfaceIdOption);
1374
1375 // relay message option
1376 Dhcp6Option relayMsgOption = new Dhcp6Option();
1377 relayMsgOption.setCode(DHCP6.OptionCode.RELAY_MSG.value());
1378 byte[] dhcp6PayloadByte = dhcp6Payload.serialize();
1379 relayMsgOption.setLength((short) dhcp6PayloadByte.length);
1380 relayMsgOption.setPayload(dhcp6Payload);
1381 Dhcp6RelayOption relayOpt = new Dhcp6RelayOption(relayMsgOption);
1382
1383 options.add(relayOpt);
1384
1385 dhcp6Relay.setOptions(options);
1386 }
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001387 private byte[] buildInterfaceId(MacAddress clientMac, short vlanId, ConnectPoint clientCp) {
1388 String inPortString = "-" + clientCp.toString() + ":";
Kalhee Kim45fede42017-09-05 19:05:06 +00001389 byte[] clientSoureMacBytes = clientMac.toBytes();
1390 byte[] inPortStringBytes = inPortString.getBytes();
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001391 byte[] vlanIdBytes = new byte[2];
1392 vlanIdBytes[0] = (byte) ((vlanId >> 8) & 0xff); // high-order byte first
1393 vlanIdBytes[1] = (byte) (vlanId & 0xff);
1394 byte[] interfaceIdBytes = new byte[clientSoureMacBytes.length + inPortStringBytes.length + vlanIdBytes.length];
Kalhee Kim45fede42017-09-05 19:05:06 +00001395
1396 System.arraycopy(clientSoureMacBytes, 0, interfaceIdBytes, 0, clientSoureMacBytes.length);
1397 System.arraycopy(inPortStringBytes, 0, interfaceIdBytes, clientSoureMacBytes.length, inPortStringBytes.length);
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001398 System.arraycopy(vlanIdBytes, 0, interfaceIdBytes, clientSoureMacBytes.length + inPortStringBytes.length,
1399 vlanIdBytes.length);
Kalhee Kim45fede42017-09-05 19:05:06 +00001400
1401 return interfaceIdBytes;
1402 }
1403
Yi Tseng525ff402017-10-23 19:39:39 -07001404 private static List<TrafficSelector> buildClientDhcpSelectors() {
1405 return Streams.concat(Dhcp4HandlerImpl.DHCP_SELECTORS.stream(),
1406 Dhcp6HandlerImpl.DHCP_SELECTORS.stream())
1407 .collect(Collectors.toList());
1408 }
1409
Kalhee Kim45fede42017-09-05 19:05:06 +00001410 private class TestDhcp6RequestPacketContext extends PacketContextAdapter {
1411
1412
1413 private InboundPacket inPacket;
1414
1415
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001416 public TestDhcp6RequestPacketContext(byte msgType, MacAddress clientMac, VlanId vlanId,
Kalhee Kim45fede42017-09-05 19:05:06 +00001417 ConnectPoint clientCp,
1418 Ip6Address clientGwAddr,
1419 int relayLevel) {
1420 super(0, null, null, false);
1421
1422 DHCP6 dhcp6 = new DHCP6();
1423 if (relayLevel > 0) {
1424 DHCP6 dhcp6Payload = new DHCP6();
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001425 buildDhcp6Packet(dhcp6Payload, msgType,
Kalhee Kim45fede42017-09-05 19:05:06 +00001426 IP_FOR_CLIENT_V6,
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001427 msgType == DHCP6.MsgType.REQUEST.value() ? PREFIX_FOR_ZERO : PREFIX_FOR_CLIENT_V6);
Kalhee Kim45fede42017-09-05 19:05:06 +00001428 DHCP6 dhcp6Parent = null;
1429 DHCP6 dhcp6Child = dhcp6Payload;
1430 for (int i = 0; i < relayLevel; i++) {
1431 dhcp6Parent = new DHCP6();
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001432 byte[] interfaceId = buildInterfaceId(clientMac, vlanId.toShort(), clientCp);
Kalhee Kim45fede42017-09-05 19:05:06 +00001433 buildRelayMsg(dhcp6Parent, DHCP6.MsgType.RELAY_FORW.value(),
1434 INTERFACE_IP_V6.ipAddress().getIp6Address(),
1435 OUTER_RELAY_IP_V6,
1436 (byte) (relayLevel - 1), interfaceId,
1437 dhcp6Child);
1438 dhcp6Child = dhcp6Parent;
1439 }
1440 if (dhcp6Parent != null) {
1441 dhcp6 = dhcp6Parent;
1442 }
1443 } else {
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001444 buildDhcp6Packet(dhcp6, msgType,
Kalhee Kim45fede42017-09-05 19:05:06 +00001445 IP_FOR_CLIENT_V6,
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001446 msgType == DHCP6.MsgType.REQUEST.value() ? PREFIX_FOR_ZERO : PREFIX_FOR_CLIENT_V6);
Kalhee Kim45fede42017-09-05 19:05:06 +00001447 }
1448
1449 UDP udp = new UDP();
1450 udp.setPayload(dhcp6);
1451 if (relayLevel > 0) {
1452 udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
1453 } else {
1454 udp.setSourcePort(UDP.DHCP_V6_CLIENT_PORT);
1455 }
1456 udp.setDestinationPort(UDP.DHCP_V6_SERVER_PORT);
1457
1458 IPv6 ipv6 = new IPv6();
1459 ipv6.setPayload(udp);
1460 ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
1461 ipv6.setDestinationAddress(SERVER_IP_V6_MCAST.toOctets());
1462 ipv6.setSourceAddress(clientGwAddr.toOctets());
1463
1464 Ethernet eth = new Ethernet();
1465 if (relayLevel > 0) {
1466 eth.setEtherType(Ethernet.TYPE_IPV6)
Kalhee Kim121ba922017-11-01 17:56:44 +00001467 .setVlanID(OUTER_RELAY_VLAN.toShort())
Kalhee Kim45fede42017-09-05 19:05:06 +00001468 .setSourceMACAddress(OUTER_RELAY_MAC)
1469 .setDestinationMACAddress(MacAddress.valueOf("33:33:00:01:00:02"))
1470 .setPayload(ipv6);
1471 } else {
1472 eth.setEtherType(Ethernet.TYPE_IPV6)
1473 .setVlanID(vlanId.toShort())
1474 .setSourceMACAddress(clientMac)
1475 .setDestinationMACAddress(MacAddress.valueOf("33:33:00:01:00:02"))
1476 .setPayload(ipv6);
1477 }
1478 this.inPacket = new DefaultInboundPacket(clientCp, eth,
1479 ByteBuffer.wrap(eth.serialize()));
1480 }
1481
1482 @Override
1483 public InboundPacket inPacket() {
1484 return this.inPacket;
1485 }
1486 }
1487
1488 /**
1489 * Generates DHCP6 REPLY packet.
1490 */
1491
1492 private class TestDhcp6ReplyPacketContext extends PacketContextAdapter {
1493 private InboundPacket inPacket;
1494
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001495 public TestDhcp6ReplyPacketContext(byte msgType, ConnectPoint clientCp, MacAddress clientMac,
Kalhee Kim45fede42017-09-05 19:05:06 +00001496 VlanId clientVlan, Ip6Address clientGwAddr,
Kalhee Kim121ba922017-11-01 17:56:44 +00001497 int relayLevel, boolean overWriteFlag, VlanId overWriteVlan) {
Kalhee Kim45fede42017-09-05 19:05:06 +00001498 super(0, null, null, false);
1499
1500
1501 DHCP6 dhcp6Payload = new DHCP6();
Kalhee Kim0c0cb0b2017-09-15 17:43:27 +00001502 buildDhcp6Packet(dhcp6Payload, msgType,
Kalhee Kim45fede42017-09-05 19:05:06 +00001503 IP_FOR_CLIENT_V6,
1504 PREFIX_FOR_CLIENT_V6);
Kalhee Kim121ba922017-11-01 17:56:44 +00001505 byte[] interfaceId = null;
1506 if (relayLevel > 0) {
1507 interfaceId = buildInterfaceId(OUTER_RELAY_MAC,
1508 overWriteFlag ? overWriteVlan.toShort() : OUTER_RELAY_VLAN.toShort(),
1509 OUTER_RELAY_CP);
1510 } else {
1511 interfaceId = buildInterfaceId(clientMac, clientVlan.toShort(), clientCp);
1512 }
Kalhee Kim45fede42017-09-05 19:05:06 +00001513 DHCP6 dhcp6 = new DHCP6();
1514 buildRelayMsg(dhcp6, DHCP6.MsgType.RELAY_REPL.value(),
Yi Tsengaa417a62017-09-08 17:22:51 -07001515 INTERFACE_IP_V6.ipAddress().getIp6Address(),
1516 CLIENT_LL_IP_V6,
1517 (byte) 0, interfaceId,
1518 dhcp6Payload);
Kalhee Kim45fede42017-09-05 19:05:06 +00001519
1520 DHCP6 dhcp6Parent = null;
1521 DHCP6 dhcp6Child = dhcp6;
1522 for (int i = 0; i < relayLevel; i++) { // relayLevel 0 : no relay
1523 dhcp6Parent = new DHCP6();
1524
1525 buildRelayMsg(dhcp6Parent, DHCP6.MsgType.RELAY_REPL.value(),
1526 INTERFACE_IP_V6.ipAddress().getIp6Address(),
1527 OUTER_RELAY_IP_V6,
1528 (byte) relayLevel, interfaceId,
1529 dhcp6Child);
1530
1531 dhcp6Child = dhcp6Parent;
1532 }
1533 if (dhcp6Parent != null) {
1534 dhcp6 = dhcp6Parent;
1535 }
1536
1537
1538 UDP udp = new UDP();
1539 udp.setPayload(dhcp6);
1540 udp.setSourcePort(UDP.DHCP_V6_SERVER_PORT);
1541 udp.setDestinationPort(UDP.DHCP_V6_CLIENT_PORT);
1542 IPv6 ipv6 = new IPv6();
1543 ipv6.setPayload(udp);
1544 ipv6.setNextHeader(IPv6.PROTOCOL_UDP);
1545 ipv6.setDestinationAddress(IP_FOR_CLIENT_V6.toOctets());
1546 ipv6.setSourceAddress(SERVER_IP_V6.toOctets());
1547 Ethernet eth = new Ethernet();
1548 if (relayLevel > 0) {
1549 eth.setEtherType(Ethernet.TYPE_IPV6)
1550 .setVlanID(SERVER_VLAN.toShort())
1551 .setSourceMACAddress(SERVER_MAC)
1552 .setDestinationMACAddress(OUTER_RELAY_MAC)
1553 .setPayload(ipv6);
1554 } else {
1555 eth.setEtherType(Ethernet.TYPE_IPV6)
1556 .setVlanID(SERVER_VLAN.toShort())
1557 .setSourceMACAddress(SERVER_MAC)
1558 .setDestinationMACAddress(CLIENT_MAC)
1559 .setPayload(ipv6);
1560 }
1561
1562 this.inPacket = new DefaultInboundPacket(SERVER_CONNECT_POINT, eth,
1563 ByteBuffer.wrap(eth.serialize()));
1564
1565 }
1566
1567 @Override
1568 public InboundPacket inPacket() {
1569 return this.inPacket;
1570 }
1571 }
1572
Yi Tseng7a38f9a2017-06-09 14:36:40 -07001573}