Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 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 | */ |
Matteo Scandolo | 57af5d1 | 2019-04-29 17:11:41 -0700 | [diff] [blame] | 16 | package org.opencord.dhcpl2relay.impl; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 17 | |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 18 | import com.google.common.collect.Lists; |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 19 | import org.easymock.EasyMock; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 23 | import org.onlab.junit.TestUtils; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 24 | import org.onlab.packet.DHCP; |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 25 | import org.onlab.packet.Ethernet; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 26 | import org.onlab.packet.IPv4; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 27 | import org.onlab.packet.UDP; |
Jonathan Hart | edbf642 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 28 | import org.onlab.packet.dhcp.DhcpOption; |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 29 | import org.onosproject.cfg.ComponentConfigService; |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 30 | import org.onosproject.cluster.LeadershipServiceAdapter; |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 31 | import org.onosproject.net.ConnectPoint; |
| 32 | import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter; |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 33 | import org.onosproject.store.service.TestStorageService; |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 34 | import org.opencord.dhcpl2relay.DhcpL2RelayEvent; |
| 35 | import org.opencord.dhcpl2relay.impl.packet.DhcpOption82; |
| 36 | |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 37 | import java.nio.ByteBuffer; |
| 38 | import java.util.HashMap; |
| 39 | import java.util.List; |
| 40 | import java.util.Map; |
| 41 | import java.util.concurrent.TimeUnit; |
| 42 | import java.util.concurrent.atomic.AtomicLong; |
| 43 | |
| 44 | import static org.junit.Assert.assertEquals; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 45 | |
| 46 | public class DhcpL2RelayTest extends DhcpL2RelayTestBase { |
| 47 | |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 48 | private DhcpL2Relay dhcpL2Relay; |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 49 | private SimpleDhcpL2RelayCountersStore store; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 50 | |
| 51 | ComponentConfigService mockConfigService = |
| 52 | EasyMock.createMock(ComponentConfigService.class); |
| 53 | |
| 54 | /** |
| 55 | * Sets up the services required by the dhcpl2relay app. |
| 56 | */ |
| 57 | @Before |
| 58 | public void setUp() { |
| 59 | dhcpL2Relay = new DhcpL2Relay(); |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 60 | dhcpL2Relay.cfgService = new DhcpL2RelayConfigTest.TestNetworkConfigRegistry(); |
Saurav Das | b4e3e10 | 2018-10-02 15:31:17 -0700 | [diff] [blame] | 61 | dhcpL2Relay.coreService = new MockCoreServiceAdapter(); |
| 62 | dhcpL2Relay.flowObjectiveService = new FlowObjectiveServiceAdapter(); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 63 | dhcpL2Relay.packetService = new MockPacketService(); |
| 64 | dhcpL2Relay.componentConfigService = mockConfigService; |
| 65 | dhcpL2Relay.deviceService = new MockDeviceService(); |
Gamze Abaka | c806c6c | 2018-12-03 12:49:46 +0000 | [diff] [blame] | 66 | dhcpL2Relay.sadisService = new MockSadisService(); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 67 | dhcpL2Relay.hostService = new MockHostService(); |
| 68 | dhcpL2Relay.mastershipService = new MockMastershipService(); |
Gamze Abaka | a64b3bc | 2020-01-31 06:51:43 +0000 | [diff] [blame] | 69 | dhcpL2Relay.dhcpL2RelayCounters = new MockDhcpL2RelayCountersStore(); |
Jonathan Hart | 617bc3e | 2020-02-14 10:42:23 -0800 | [diff] [blame^] | 70 | dhcpL2Relay.storageService = new TestStorageService(); |
| 71 | dhcpL2Relay.leadershipService = new LeadershipServiceAdapter(); |
Jonathan Hart | c36c955 | 2018-07-31 15:07:53 -0400 | [diff] [blame] | 72 | TestUtils.setField(dhcpL2Relay, "eventDispatcher", new TestEventDispatcher()); |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 73 | dhcpL2Relay.refreshService = new MockExecutor(dhcpL2Relay.refreshService); |
| 74 | dhcpL2Relay.activate(new DhcpL2RelayTestBase.MockComponentContext()); |
| 75 | store = new SimpleDhcpL2RelayCountersStore(); |
| 76 | TestUtils.setField(store, "eventDispatcher", new TestEventDispatcher()); |
| 77 | store.activate(); |
| 78 | dhcpL2Relay.dhcpL2RelayCounters = this.store; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Tears down the dhcpL2Relay application. |
| 83 | */ |
| 84 | @After |
| 85 | public void tearDown() { |
| 86 | dhcpL2Relay.deactivate(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Tests the DHCP relay app by sending DHCP discovery Packet. |
| 91 | * |
| 92 | * @throws Exception when an unhandled error occurs |
| 93 | */ |
| 94 | @Test |
| 95 | public void testDhcpDiscover() throws Exception { |
| 96 | // (1) Sending DHCP discover packet |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 97 | Ethernet discoverPacket = constructDhcpDiscoverPacket(CLIENT_MAC); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 98 | |
| 99 | sendPacket(discoverPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 100 | |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 101 | Ethernet discoverRelayed = (Ethernet) getPacket(); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 102 | compareClientPackets(discoverPacket, discoverRelayed); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Tests the DHCP relay app by sending DHCP Request Packet. |
| 107 | * |
| 108 | * @throws Exception when an unhandled error occurs |
| 109 | */ |
| 110 | @Test |
| 111 | public void testDhcpRequest() throws Exception { |
| 112 | // (1) Sending DHCP discover packet |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 113 | Ethernet requestPacket = constructDhcpRequestPacket(CLIENT_MAC); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 114 | |
| 115 | sendPacket(requestPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 116 | |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 117 | Ethernet requestRelayed = (Ethernet) getPacket(); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 118 | compareClientPackets(requestPacket, requestRelayed); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Tests the DHCP relay app by sending DHCP Offer Packet. |
| 123 | * |
| 124 | * @throws Exception when an unhandled error occurs |
| 125 | */ |
| 126 | @Test |
| 127 | public void testDhcpOffer() { |
| 128 | // (1) Sending DHCP discover packet |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 129 | Ethernet offerPacket = constructDhcpOfferPacket(SERVER_MAC, |
| 130 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 131 | |
| 132 | sendPacket(offerPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 133 | |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 134 | Ethernet offerRelayed = (Ethernet) getPacket(); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 135 | compareServerPackets(offerPacket, offerRelayed); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Tests the DHCP relay app by sending DHCP Ack Packet. |
| 140 | * |
| 141 | * @throws Exception when an unhandled error occurs |
| 142 | */ |
| 143 | @Test |
| 144 | public void testDhcpAck() { |
| 145 | |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 146 | Ethernet ackPacket = constructDhcpAckPacket(SERVER_MAC, |
| 147 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 148 | |
| 149 | sendPacket(ackPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 150 | |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 151 | Ethernet ackRelayed = (Ethernet) getPacket(); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 152 | compareServerPackets(ackPacket, ackRelayed); |
| 153 | } |
| 154 | |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 155 | /** |
Arjun E K | 05ad20b | 2020-03-13 13:25:17 +0000 | [diff] [blame] | 156 | * Tests the DHCP relay app by sending DHCP Nak Packet. |
| 157 | * |
| 158 | * @throws Exception when an unhandled error occurs |
| 159 | */ |
| 160 | @Test |
| 161 | public void testDhcpNak() { |
| 162 | |
| 163 | Ethernet nakPacket = constructDhcpNakPacket(SERVER_MAC, |
| 164 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
| 165 | |
| 166 | sendPacket(nakPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 167 | |
| 168 | Ethernet nakRelayed = (Ethernet) getPacket(); |
| 169 | compareServerPackets(nakPacket, nakRelayed); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Tests the DHCP relay app by sending DHCP Decline Packet. |
| 174 | * |
| 175 | * @throws Exception when an unhandled error occurs |
| 176 | */ |
| 177 | @Test |
| 178 | public void testDhcpDecline() { |
| 179 | |
| 180 | Ethernet declinePacket = constructDhcpDeclinePacket(CLIENT_MAC); |
| 181 | |
| 182 | sendPacket(declinePacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 183 | |
| 184 | Ethernet declineRelayed = (Ethernet) getPacket(); |
| 185 | compareClientPackets(declinePacket, declineRelayed); |
| 186 | } |
| 187 | |
| 188 | /** |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 189 | * Tests the DHCP global counters. |
| 190 | */ |
| 191 | @Test |
| 192 | public void testDhcpGlobalCounters() { |
| 193 | long discoveryValue = 0; |
| 194 | long offerValue = 0; |
| 195 | long requestValue = 0; |
| 196 | long ackValue = 0; |
| 197 | |
| 198 | Ethernet discoverPacket = constructDhcpDiscoverPacket(CLIENT_MAC); |
| 199 | Ethernet offerPacket = constructDhcpOfferPacket(SERVER_MAC, |
| 200 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
| 201 | Ethernet requestPacket = constructDhcpRequestPacket(CLIENT_MAC); |
| 202 | Ethernet ackPacket = constructDhcpAckPacket(SERVER_MAC, |
| 203 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
| 204 | |
| 205 | sendPacket(discoverPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 206 | sendPacket(offerPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 207 | sendPacket(requestPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 208 | sendPacket(ackPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 209 | |
| 210 | Map<DhcpL2RelayCountersIdentifier, AtomicLong> countersMap = dhcpL2Relay.dhcpL2RelayCounters.getCountersMap(); |
| 211 | discoveryValue = countersMap.get(new DhcpL2RelayCountersIdentifier(DhcpL2RelayEvent.GLOBAL_COUNTER, |
| 212 | DhcpL2RelayCounters.valueOf("DHCPDISCOVER"))).longValue(); |
| 213 | offerValue = countersMap.get(new DhcpL2RelayCountersIdentifier(DhcpL2RelayEvent.GLOBAL_COUNTER, |
| 214 | DhcpL2RelayCounters.valueOf("DHCPOFFER"))).longValue(); |
| 215 | requestValue = countersMap.get(new DhcpL2RelayCountersIdentifier(DhcpL2RelayEvent.GLOBAL_COUNTER, |
| 216 | DhcpL2RelayCounters.valueOf("DHCPREQUEST"))).longValue(); |
| 217 | ackValue = countersMap.get(new DhcpL2RelayCountersIdentifier(DhcpL2RelayEvent.GLOBAL_COUNTER, |
| 218 | DhcpL2RelayCounters.valueOf("DHCPACK"))).longValue(); |
| 219 | |
| 220 | assertEquals((long) 1, discoveryValue); |
| 221 | assertEquals((long) 1, offerValue); |
| 222 | assertEquals((long) 1, requestValue); |
| 223 | assertEquals((long) 1, ackValue); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Tests the DHCP per subscriber counters. |
| 228 | * |
| 229 | */ |
| 230 | @Test |
| 231 | public void testDhcpPerSubscriberCounters() { |
| 232 | long discoveryValue; |
| 233 | long offerValue; |
| 234 | long requestValue; |
| 235 | long ackValue; |
| 236 | |
| 237 | Ethernet discoverPacket = constructDhcpDiscoverPacket(CLIENT_MAC); |
| 238 | Ethernet offerPacket = constructDhcpOfferPacket(SERVER_MAC, |
| 239 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
| 240 | Ethernet requestPacket = constructDhcpRequestPacket(CLIENT_MAC); |
| 241 | Ethernet ackPacket = constructDhcpAckPacket(SERVER_MAC, |
| 242 | CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS); |
| 243 | |
| 244 | sendPacket(discoverPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 245 | sendPacket(offerPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 246 | sendPacket(requestPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 247 | sendPacket(ackPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1)); |
| 248 | |
| 249 | Map<DhcpL2RelayCountersIdentifier, AtomicLong> countersMap = dhcpL2Relay.dhcpL2RelayCounters.getCountersMap(); |
| 250 | discoveryValue = countersMap.get(new DhcpL2RelayCountersIdentifier(CLIENT_ID_1, |
| 251 | DhcpL2RelayCounters.valueOf("DHCPDISCOVER"))).longValue(); |
| 252 | offerValue = countersMap.get(new DhcpL2RelayCountersIdentifier(CLIENT_ID_1, |
| 253 | DhcpL2RelayCounters.valueOf("DHCPOFFER"))).longValue(); |
| 254 | requestValue = countersMap.get(new DhcpL2RelayCountersIdentifier(CLIENT_ID_1, |
| 255 | DhcpL2RelayCounters.valueOf("DHCPREQUEST"))).longValue(); |
| 256 | ackValue = countersMap.get(new DhcpL2RelayCountersIdentifier(CLIENT_ID_1, |
| 257 | DhcpL2RelayCounters.valueOf("DHCPACK"))).longValue(); |
| 258 | |
| 259 | assertEquals((long) 1, discoveryValue); |
| 260 | assertEquals((long) 1, offerValue); |
| 261 | assertEquals((long) 1, requestValue); |
| 262 | assertEquals((long) 1, ackValue); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Tests the schedule function to publish the counters to kafka. |
| 267 | * |
| 268 | */ |
| 269 | @Test |
| 270 | public void testSchedulePublishCountersToKafka() { |
| 271 | MockExecutor executor = new MockExecutor(dhcpL2Relay.refreshService); |
| 272 | dhcpL2Relay.refreshTask = executor.scheduleWithFixedDelay( |
| 273 | dhcpL2Relay.publishCountersToKafka, 0, 10, TimeUnit.SECONDS); |
| 274 | executor.assertLastMethodCalled("scheduleWithFixedDelay", 0, 10, TimeUnit.SECONDS); |
| 275 | } |
| 276 | |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 277 | public void compareClientPackets(Ethernet sent, Ethernet relayed) { |
| 278 | sent.setSourceMACAddress(OLT_MAC_ADDRESS); |
| 279 | sent.setQinQVID(CLIENT_S_TAG.toShort()); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 280 | sent.setVlanID(CLIENT_C_TAG.toShort()); |
Gamze Abaka | a64b3bc | 2020-01-31 06:51:43 +0000 | [diff] [blame] | 281 | sent.setPriorityCode((byte) CLIENT_C_PBIT); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 282 | |
| 283 | IPv4 ipv4Packet = (IPv4) sent.getPayload(); |
| 284 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
| 285 | DHCP dhcpPacket = (DHCP) udpPacket.getPayload(); |
| 286 | |
Jonathan Hart | edbf642 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 287 | List<DhcpOption> options = Lists.newArrayList(dhcpPacket.getOptions()); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 288 | DhcpOption82 option82 = new DhcpOption82(); |
| 289 | option82.setAgentCircuitId(CLIENT_CIRCUIT_ID); |
| 290 | |
Jonathan Hart | edbf642 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 291 | DhcpOption option = new DhcpOption() |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 292 | .setCode(DHCP.DHCPOptionCode.OptionCode_CircuitID.getValue()) |
| 293 | .setData(option82.toByteArray()) |
| 294 | .setLength(option82.length()); |
| 295 | |
| 296 | options.add(options.size() - 1, option); |
| 297 | dhcpPacket.setOptions(options); |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 298 | assertEquals(sent, relayed); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 299 | |
| 300 | } |
| 301 | |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 302 | public void compareServerPackets(Ethernet sent, Ethernet relayed) { |
| 303 | sent.setDestinationMACAddress(CLIENT_MAC); |
Gamze Abaka | a64b3bc | 2020-01-31 06:51:43 +0000 | [diff] [blame] | 304 | sent.setQinQVID(NOT_PROVIDED); |
| 305 | sent.setQinQPriorityCode((byte) NOT_PROVIDED); |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 306 | sent.setVlanID(CLIENT_C_TAG.toShort()); |
| 307 | |
| 308 | final ByteBuffer byteBuffer = ByteBuffer.wrap(sent.serialize()); |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 309 | Ethernet expectedPacket = null; |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 310 | try { |
Deepa Vaddireddy | 5f278d6 | 2017-08-30 05:59:39 +0530 | [diff] [blame] | 311 | expectedPacket = Ethernet.deserializer().deserialize(byteBuffer.array(), |
Amit Ghosh | 8951f04 | 2017-08-10 13:48:10 +0100 | [diff] [blame] | 312 | 0, byteBuffer.array().length); |
| 313 | } catch (Exception e) { |
| 314 | } |
| 315 | assertEquals(expectedPacket, relayed); |
| 316 | |
| 317 | } |
Gamze Abaka | a64b3bc | 2020-01-31 06:51:43 +0000 | [diff] [blame] | 318 | |
| 319 | private class MockDhcpL2RelayCountersStore implements DhcpL2RelayCountersStore { |
| 320 | @Override |
| 321 | public void initCounters(String counterClass) { |
| 322 | |
| 323 | } |
| 324 | |
| 325 | @Override |
| 326 | public void incrementCounter(String counterClass, DhcpL2RelayCounters counterType) { |
| 327 | |
| 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public void setCounter(String counterClass, DhcpL2RelayCounters counterType, Long value) { |
| 332 | |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public Map<DhcpL2RelayCountersIdentifier, AtomicLong> getCountersMap() { |
| 337 | return new HashMap<>(); |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public void resetCounters(String counterClass) { |
| 342 | |
| 343 | } |
| 344 | } |
Marcos Aurelio Carrero | eaf02b8 | 2019-11-25 13:34:25 -0300 | [diff] [blame] | 345 | } |