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