TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.proxyarp; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertTrue; |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 5 | import static org.junit.Assert.fail; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 6 | |
| 7 | import java.net.InetAddress; |
| 8 | import java.net.UnknownHostException; |
| 9 | import java.nio.ByteBuffer; |
| 10 | import java.util.ArrayList; |
| 11 | import java.util.HashMap; |
| 12 | import java.util.List; |
| 13 | import java.util.Map; |
| 14 | |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 16 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 17 | import net.floodlightcontroller.restserver.IRestApiService; |
| 18 | import net.floodlightcontroller.util.MACAddress; |
| 19 | import net.onrc.onos.api.packet.IPacketService; |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 20 | import net.onrc.onos.apps.proxyarp.web.ArpWebRoutable; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 21 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 22 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 23 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
| 24 | import net.onrc.onos.core.devicemanager.IOnosDeviceService; |
| 25 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService; |
| 26 | import net.onrc.onos.core.main.config.IConfigInfoService; |
| 27 | import net.onrc.onos.core.packet.ARP; |
| 28 | import net.onrc.onos.core.packet.Ethernet; |
| 29 | import net.onrc.onos.core.packet.IPv4; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 30 | import net.onrc.onos.core.topology.Device; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 31 | import net.onrc.onos.core.topology.ITopologyService; |
| 32 | import net.onrc.onos.core.topology.Topology; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.topology.Port; |
| 34 | import net.onrc.onos.core.topology.Switch; |
| 35 | |
| 36 | import org.easymock.EasyMock; |
| 37 | import org.junit.After; |
| 38 | import org.junit.Before; |
| 39 | import org.junit.Test; |
| 40 | import org.junit.runner.RunWith; |
| 41 | import org.powermock.api.easymock.PowerMock; |
| 42 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 43 | import org.powermock.modules.junit4.PowerMockRunner; |
| 44 | |
| 45 | @RunWith(PowerMockRunner.class) |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 46 | @PrepareForTest({ ProxyArpManager.class, ArpCache.class }) |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 47 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 48 | public class ProxyArpManagerTest { |
| 49 | String defaultStrAgingMsec = "60000"; |
| 50 | String defaultStrCleanupMsec = "60000"; |
| 51 | |
| 52 | ProxyArpManager arpManager; |
| 53 | FloodlightModuleContext context; |
| 54 | IFloodlightProviderService floodligthProviderService; |
| 55 | IConfigInfoService configInfoService; |
| 56 | IRestApiService restApiService; |
| 57 | IDatagridService datagridService; |
| 58 | IFlowPusherService flowPusherService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 59 | ITopologyService topologyService; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 60 | IOnosDeviceService onosDeviceService; |
| 61 | IPacketService packetService; |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 62 | Map<String, String> configMap; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 63 | |
| 64 | String srcStrMac, dstStrMac, cachedStrMac1, cachedStrMac2, srcStrIp, dstStrIp, cachedStrIp1, cachedStrIp2; |
| 65 | byte[] srcByteMac, dstByteMac; |
| 66 | MACAddress dstMac, srcMac, cachedMac1, cachedMac2; |
| 67 | InetAddress srcIp, dstIp, cachedIp1, cachedIp2; |
| 68 | Long sw1Dpid; |
| 69 | Short sw1Inport, sw1Outport; |
| 70 | Short vlanId; |
| 71 | ARP arpRequest, arpReply, rarpRequest; |
| 72 | Ethernet ethArpRequest, ethArpReply, ethRarpRequest, ethArpOtherOp; |
| 73 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 74 | Topology topology; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 75 | IEventChannel eg; |
| 76 | IEventChannelListener el; |
| 77 | Device dev1; |
| 78 | Port inPort1, outPort1; |
| 79 | Switch sw1; |
| 80 | ArpCache arpCache; |
| 81 | List<String> arpCacheComparisonList; |
| 82 | |
| 83 | @Before |
| 84 | public void setUp() throws Exception { |
| 85 | makeTestedObject(); |
| 86 | makeMock(); |
| 87 | prepareExpectForInit(); |
| 88 | prepareExpectForStartUp(); |
| 89 | prepareExpectForGeneral(); |
| 90 | } |
| 91 | |
| 92 | private void makeTestedObject() { |
| 93 | //Made tested values |
| 94 | srcStrMac = "00:00:00:00:00:01"; |
| 95 | dstStrMac = "00:00:00:00:00:02"; |
| 96 | cachedStrMac1 = "00:00:00:00:00:03"; |
| 97 | cachedStrMac2 = "00:00:00:00:00:04"; |
| 98 | srcStrIp = "192.168.0.1"; |
| 99 | dstStrIp = "192.168.0.2"; |
| 100 | cachedStrIp1 = "192.168.0.3"; |
| 101 | cachedStrIp2 = "192.168.0.4"; |
| 102 | srcByteMac = Ethernet.toMACAddress(srcStrMac); |
| 103 | dstByteMac = Ethernet.toMACAddress(dstStrMac); |
| 104 | dstMac = new MACAddress(dstByteMac); |
| 105 | srcMac = new MACAddress(srcByteMac); |
| 106 | cachedMac1 = new MACAddress(Ethernet.toMACAddress(cachedStrMac1)); |
| 107 | cachedMac2 = new MACAddress(Ethernet.toMACAddress(cachedStrMac2)); |
| 108 | srcIp = null; |
| 109 | dstIp = null; |
| 110 | cachedIp1 = null; |
| 111 | cachedIp2 = null; |
| 112 | try { |
| 113 | srcIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(srcStrIp)); |
| 114 | dstIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(dstStrIp)); |
| 115 | cachedIp1 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp1)); |
| 116 | cachedIp2 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp2)); |
| 117 | } catch (UnknownHostException e) { |
| 118 | e.printStackTrace(); |
| 119 | } |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 120 | sw1Dpid = 1L; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 121 | sw1Inport = 1; |
| 122 | sw1Outport = 2; |
| 123 | vlanId = 1; |
| 124 | |
| 125 | //Made tested packets |
| 126 | arpRequest = new ARP() |
| 127 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 128 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 129 | .setHardwareAddressLength((byte) 6) |
| 130 | .setProtocolAddressLength((byte) 4) |
| 131 | .setOpCode(ARP.OP_REQUEST) |
| 132 | .setSenderHardwareAddress(srcByteMac) |
| 133 | .setSenderProtocolAddress(srcIp.getAddress()) |
| 134 | .setTargetProtocolAddress(dstIp.getAddress()) |
| 135 | .setTargetHardwareAddress(dstByteMac); |
| 136 | |
| 137 | ethArpRequest = (Ethernet) new Ethernet() |
| 138 | .setSourceMACAddress(srcStrMac) |
| 139 | .setDestinationMACAddress(dstStrMac) |
| 140 | .setEtherType(Ethernet.TYPE_ARP) |
| 141 | .setVlanID((short) 0) |
| 142 | .setPayload(arpRequest); |
| 143 | |
| 144 | arpReply = new ARP() |
| 145 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 146 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 147 | .setHardwareAddressLength((byte) 6) |
| 148 | .setProtocolAddressLength((byte) 4) |
| 149 | .setOpCode(ARP.OP_RARP_REPLY) |
| 150 | .setSenderHardwareAddress(srcByteMac) |
| 151 | .setSenderProtocolAddress(srcIp.getAddress()) |
| 152 | .setTargetProtocolAddress(dstIp.getAddress()) |
| 153 | .setTargetHardwareAddress(dstByteMac); |
| 154 | |
| 155 | ethArpReply = (Ethernet) new Ethernet() |
| 156 | .setSourceMACAddress(srcStrMac) |
| 157 | .setDestinationMACAddress(dstStrMac) |
| 158 | .setEtherType(Ethernet.TYPE_ARP) |
| 159 | .setVlanID((short) 0) |
| 160 | .setPayload(arpReply); |
| 161 | |
| 162 | rarpRequest = new ARP() |
| 163 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 164 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 165 | .setHardwareAddressLength((byte) 6) |
| 166 | .setProtocolAddressLength((byte) 4) |
| 167 | .setOpCode(ARP.OP_RARP_REQUEST) |
| 168 | .setSenderHardwareAddress(srcByteMac) |
| 169 | .setSenderProtocolAddress(srcIp.getAddress()) |
| 170 | .setTargetProtocolAddress(dstIp.getAddress()) |
| 171 | .setTargetHardwareAddress(dstByteMac); |
| 172 | |
| 173 | ethRarpRequest = (Ethernet) new Ethernet() |
| 174 | .setSourceMACAddress(srcStrMac) |
| 175 | .setDestinationMACAddress(dstStrMac) |
| 176 | .setEtherType(Ethernet.TYPE_RARP) |
| 177 | .setVlanID((short) 0) |
| 178 | .setPayload(rarpRequest); |
| 179 | |
| 180 | ethArpOtherOp = (Ethernet) new Ethernet() |
| 181 | .setSourceMACAddress(srcStrMac) |
| 182 | .setDestinationMACAddress(dstStrMac) |
| 183 | .setEtherType(Ethernet.TYPE_ARP) |
| 184 | .setVlanID((short) 0) |
| 185 | .setPayload(rarpRequest); |
| 186 | |
| 187 | //Made tested objects |
| 188 | arpCache = new ArpCache(); |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 189 | arpCache.setArpEntryTimeoutConfig(Long.parseLong(defaultStrCleanupMsec)); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 190 | arpCache.update(cachedIp1, cachedMac1); |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 191 | arpCache.update(cachedIp2, cachedMac2); |
| 192 | |
| 193 | arpCacheComparisonList = new ArrayList<String>(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 194 | arpCacheComparisonList.add(cachedStrIp1 |
| 195 | + " => " |
| 196 | + cachedStrMac1 |
| 197 | + " : VALID"); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 198 | arpCacheComparisonList.add(cachedStrIp2 |
| 199 | + " => " |
| 200 | + cachedStrMac2 |
| 201 | + " : VALID"); |
| 202 | |
| 203 | arpManager = new ProxyArpManager(); |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 204 | configMap = new HashMap<String, String>(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | private void makeMock() { |
| 208 | //Mock floodlight modules |
| 209 | context = EasyMock.createMock(FloodlightModuleContext.class); |
| 210 | floodligthProviderService = EasyMock.createMock(IFloodlightProviderService.class); |
| 211 | configInfoService = EasyMock.createMock(IConfigInfoService.class); |
| 212 | restApiService = EasyMock.createMock(IRestApiService.class); |
| 213 | datagridService = EasyMock.createMock(IDatagridService.class); |
| 214 | flowPusherService = EasyMock.createMock(IFlowPusherService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 215 | topologyService = EasyMock.createMock(ITopologyService.class); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 216 | onosDeviceService = EasyMock.createMock(IOnosDeviceService.class); |
| 217 | packetService = EasyMock.createMock(IPacketService.class); |
| 218 | eg = EasyMock.createMock(IEventChannel.class); |
| 219 | el = EasyMock.createMock(IEventChannelListener.class); |
| 220 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 221 | //Mock Topology related data |
| 222 | topology = EasyMock.createMock(Topology.class); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 223 | dev1 = EasyMock.createMock(Device.class); |
| 224 | inPort1 = EasyMock.createMock(Port.class); |
| 225 | outPort1 = EasyMock.createMock(Port.class); |
| 226 | sw1 = EasyMock.createMock(Switch.class); |
| 227 | } |
| 228 | |
| 229 | private void prepareExpectForGeneral() { |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 230 | EasyMock.expect(inPort1.getNumber()).andReturn((long) sw1Inport).anyTimes(); |
| 231 | EasyMock.expect(outPort1.getNumber()).andReturn((long) sw1Outport).anyTimes(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 232 | EasyMock.expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes(); |
| 233 | EasyMock.expect(outPort1.getIncomingLink()).andReturn(null).anyTimes(); |
| 234 | EasyMock.expect(outPort1.getSwitch()).andReturn(sw1).anyTimes(); |
| 235 | EasyMock.expect(sw1.getDpid()).andReturn(sw1Dpid).anyTimes(); |
| 236 | } |
| 237 | |
| 238 | private void prepareExpectForInit() { |
| 239 | EasyMock.expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodligthProviderService); |
| 240 | EasyMock.expect(context.getServiceImpl(IConfigInfoService.class)).andReturn(configInfoService); |
| 241 | EasyMock.expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApiService); |
| 242 | EasyMock.expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService); |
| 243 | EasyMock.expect(context.getServiceImpl(IFlowPusherService.class)).andReturn(flowPusherService); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 244 | EasyMock.expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 245 | EasyMock.expect(context.getServiceImpl(IOnosDeviceService.class)).andReturn(onosDeviceService); |
| 246 | EasyMock.expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService); |
| 247 | } |
| 248 | |
| 249 | private void prepareExpectForStartUp() { |
| 250 | try { |
| 251 | PowerMock.expectNew(ArpCache.class).andReturn(arpCache); |
| 252 | } catch (Exception e) { |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 253 | fail("Exception:" + e.getMessage()); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 254 | } |
| 255 | PowerMock.replayAll(); |
| 256 | EasyMock.expect(configInfoService.getVlan()).andReturn(vlanId); |
| 257 | restApiService.addRestletRoutable(EasyMock.isA(ArpWebRoutable.class)); |
| 258 | EasyMock.expectLastCall(); |
| 259 | packetService.registerPacketListener(arpManager); |
| 260 | EasyMock.expectLastCall(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 261 | EasyMock.expect(topologyService.getTopology()).andReturn(topology); |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 262 | EasyMock.expect(datagridService.addListener(EasyMock.<String>anyObject(), |
| 263 | EasyMock.isA(IEventChannelListener.class), |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 264 | (Class) EasyMock.anyObject(), (Class) EasyMock.anyObject())).andReturn(eg).anyTimes(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 265 | List<ArpCacheNotification> list = new ArrayList<ArpCacheNotification>(); |
| 266 | EasyMock.expect(eg.getAllEntries()).andReturn(list); |
| 267 | } |
| 268 | |
| 269 | private void prepareExpectForLearnArp() { |
| 270 | eg.addEntry(EasyMock.eq(srcIp.toString()), EasyMock.isA(ArpCacheNotification.class)); |
| 271 | EasyMock.expectLastCall(); |
| 272 | } |
| 273 | |
| 274 | @After |
| 275 | public void tearDown() throws Exception { |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 276 | arpCache = null; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Test |
| 280 | public void testConfigTimeWithNoConfig() { |
| 281 | Map<String, String> config = new HashMap<String, String>(); |
| 282 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 283 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 284 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 285 | restApiService, datagridService, flowPusherService, |
| 286 | topologyService, onosDeviceService, packetService, topology, eg, |
| 287 | el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 288 | arpManager.init(context); |
| 289 | arpManager.startUp(context); |
| 290 | assertEquals(defaultStrAgingMsec, String.valueOf(arpManager.getArpEntryTimeout())); |
| 291 | assertEquals(defaultStrCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod())); |
| 292 | } |
| 293 | |
| 294 | @Test |
| 295 | public void testConfigTimeWithWrongParameter() { |
| 296 | Map<String, String> config = new HashMap<String, String>(); |
| 297 | String strAgingMsec = "aaaaa"; |
| 298 | String strCleanupMsec = "bbbbb"; |
| 299 | config.put("agingmsec", strAgingMsec); |
| 300 | config.put("cleanupmsec", strCleanupMsec); |
| 301 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 302 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 303 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 304 | restApiService, datagridService, flowPusherService, |
| 305 | topologyService, onosDeviceService, packetService, topology, |
| 306 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 307 | arpManager.init(context); |
| 308 | arpManager.startUp(context); |
| 309 | assertEquals(defaultStrAgingMsec, String.valueOf(arpManager.getArpEntryTimeout())); |
| 310 | assertEquals(defaultStrCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod())); |
| 311 | } |
| 312 | |
| 313 | @Test |
| 314 | public void testConfigTime() { |
| 315 | String strAgingMsec = "10000"; |
| 316 | String strCleanupMsec = "10000"; |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 317 | configMap.put("agingmsec", strAgingMsec); |
| 318 | configMap.put("cleanupmsec", strCleanupMsec); |
| 319 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(configMap); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 320 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 321 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 322 | restApiService, datagridService, flowPusherService, |
| 323 | topologyService, onosDeviceService, packetService, topology, |
| 324 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 325 | arpManager.init(context); |
| 326 | arpManager.startUp(context); |
| 327 | assertEquals(strAgingMsec, String.valueOf(arpManager.getArpEntryTimeout())); |
| 328 | assertEquals(strCleanupMsec, String.valueOf(arpManager.getArpCleaningTimerPeriod())); |
| 329 | } |
| 330 | |
| 331 | @Test |
| 332 | public void testGetMacAddress() { |
| 333 | Map<String, String> config = new HashMap<String, String>(); |
| 334 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 335 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 336 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 337 | restApiService, datagridService, flowPusherService, |
| 338 | topologyService, onosDeviceService, packetService, topology, |
| 339 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 340 | arpManager.init(context); |
| 341 | arpManager.startUp(context); |
| 342 | MACAddress mac = arpManager.getMacAddress(cachedIp1); |
| 343 | assertEquals(cachedMac1, mac); |
| 344 | } |
| 345 | |
| 346 | @Test |
| 347 | public void testGetMappings() { |
| 348 | Map<String, String> config = new HashMap<String, String>(); |
| 349 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 350 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 351 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 352 | restApiService, datagridService, flowPusherService, |
| 353 | topologyService, onosDeviceService, packetService, topology, |
| 354 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 355 | arpManager.init(context); |
| 356 | arpManager.startUp(context); |
| 357 | List<String> list = arpManager.getMappings(); |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 358 | for (String str : list) { |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 359 | assertTrue(arpCacheComparisonList.contains(str)); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | @Test |
| 364 | public void testReceivePacketWithNoArpPacket() { |
| 365 | Map<String, String> config = new HashMap<String, String>(); |
| 366 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 367 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 368 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 369 | restApiService, datagridService, flowPusherService, |
| 370 | topologyService, onosDeviceService, packetService, topology, |
| 371 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 372 | arpManager.init(context); |
| 373 | arpManager.startUp(context); |
| 374 | arpManager.receive(sw1, inPort1, ethRarpRequest); |
| 375 | } |
| 376 | |
| 377 | @Test |
| 378 | public void testReceivePacketWithOtherOpCode() { |
| 379 | Map<String, String> config = new HashMap<String, String>(); |
| 380 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 381 | |
| 382 | prepareExpectForLearnArp(); |
| 383 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 384 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 385 | restApiService, datagridService, flowPusherService, |
| 386 | topologyService, onosDeviceService, packetService, topology, |
| 387 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 388 | arpManager.init(context); |
| 389 | arpManager.startUp(context); |
| 390 | arpManager.receive(sw1, inPort1, ethArpOtherOp); |
| 391 | } |
| 392 | |
| 393 | @Test |
| 394 | public void testClassifyPacketToSendArpReplyNotification() { |
| 395 | Map<String, String> config = new HashMap<String, String>(); |
| 396 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 397 | |
| 398 | prepareExpectForLearnArp(); |
| 399 | |
| 400 | ArpReplyNotification value = |
| 401 | new ArpReplyNotification(ByteBuffer.wrap(dstIp.getAddress()).getInt(), dstMac); |
| 402 | eg.addTransientEntry(srcMac.toLong(), value); |
| 403 | EasyMock.expectLastCall(); |
| 404 | EasyMock.expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService); |
| 405 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 406 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 407 | restApiService, datagridService, flowPusherService, |
| 408 | topologyService, onosDeviceService, packetService, topology, |
| 409 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 410 | arpManager.init(context); |
| 411 | arpManager.startUp(context); |
| 412 | arpManager.receive(sw1, inPort1, ethArpReply); |
| 413 | } |
| 414 | |
| 415 | @Test |
| 416 | public void testClassifyPacketToHandleArpRequest() { |
| 417 | Map<String, String> config = new HashMap<String, String>(); |
| 418 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 419 | |
| 420 | prepareExpectForLearnArp(); |
| 421 | |
| 422 | EasyMock.expect(configInfoService.fromExternalNetwork(EasyMock.anyLong(), EasyMock.anyShort())).andReturn(true); |
| 423 | EasyMock.expect(configInfoService.isInterfaceAddress(dstIp)).andReturn(false); |
| 424 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 425 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 426 | restApiService, datagridService, flowPusherService, |
| 427 | topologyService, onosDeviceService, packetService, topology, |
| 428 | eg, el, dev1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 429 | arpManager.init(context); |
| 430 | arpManager.startUp(context); |
| 431 | arpManager.receive(sw1, inPort1, ethArpRequest); |
| 432 | } |
| 433 | |
| 434 | @Test |
| 435 | public void testClassifyPacketToHandleArpRequest2() { |
| 436 | List<Port> portList = new ArrayList<Port>(); |
| 437 | portList.add(outPort1); |
| 438 | |
| 439 | Map<String, String> config = new HashMap<String, String>(); |
| 440 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 441 | |
| 442 | prepareExpectForLearnArp(); |
| 443 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 444 | EasyMock.expect(configInfoService.fromExternalNetwork( |
| 445 | EasyMock.anyLong(), EasyMock.anyShort())).andReturn(false); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 446 | topology.acquireReadLock(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 447 | EasyMock.expectLastCall(); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 448 | EasyMock.expect(topology.getDeviceByMac(dstMac)).andReturn(dev1); |
| 449 | topology.releaseReadLock(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 450 | EasyMock.expectLastCall(); |
| 451 | EasyMock.expect(dev1.getAttachmentPoints()).andReturn(portList); |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 452 | eg.addTransientEntry(EasyMock.anyLong(), EasyMock.anyObject()); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 453 | EasyMock.expectLastCall(); |
| 454 | |
| 455 | EasyMock.replay(context, configInfoService, restApiService, floodligthProviderService, |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 456 | topologyService, datagridService, eg, topology, dev1, inPort1, outPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 457 | arpManager.init(context); |
| 458 | arpManager.startUp(context); |
| 459 | arpManager.receive(sw1, inPort1, ethArpRequest); |
| 460 | } |
| 461 | } |