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 | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 5 | |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 6 | import java.net.InetAddress; |
| 7 | import java.net.UnknownHostException; |
| 8 | import java.nio.ByteBuffer; |
| 9 | import java.util.ArrayList; |
| 10 | import java.util.HashMap; |
| 11 | import java.util.List; |
| 12 | import java.util.Map; |
| 13 | |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 14 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 15 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 16 | import net.floodlightcontroller.restserver.IRestApiService; |
| 17 | import net.floodlightcontroller.util.MACAddress; |
| 18 | import net.onrc.onos.api.packet.IPacketService; |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 19 | import net.onrc.onos.apps.proxyarp.web.ArpWebRoutable; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 20 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 21 | import net.onrc.onos.core.datagrid.IEventChannel; |
| 22 | import net.onrc.onos.core.datagrid.IEventChannelListener; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 23 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService; |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 24 | import net.onrc.onos.core.hostmanager.IHostService; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 25 | import net.onrc.onos.core.main.config.IConfigInfoService; |
| 26 | import net.onrc.onos.core.packet.ARP; |
| 27 | import net.onrc.onos.core.packet.Ethernet; |
| 28 | import net.onrc.onos.core.packet.IPv4; |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 29 | import net.onrc.onos.core.topology.Host; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 30 | import net.onrc.onos.core.topology.ITopologyService; |
| 31 | import net.onrc.onos.core.topology.Topology; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.topology.Port; |
| 33 | import net.onrc.onos.core.topology.Switch; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 34 | import net.onrc.onos.core.util.Dpid; |
| 35 | import net.onrc.onos.core.util.PortNumber; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 36 | |
| 37 | import org.easymock.EasyMock; |
| 38 | import org.junit.After; |
| 39 | import org.junit.Before; |
| 40 | import org.junit.Test; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 41 | |
Yuta HIGUCHI | 33a0497 | 2014-06-03 13:00:15 -0700 | [diff] [blame] | 42 | // XXX Commented out as workaround for PowerMock + Hazelcast issue. |
| 43 | //@RunWith(PowerMockRunner.class) |
| 44 | //@PowerMockIgnore({ "net.onrc.onos.core.datastore.*", "com.hazelcast.*" }) |
| 45 | //@PrepareOnlyThisForTest({ ProxyArpManager.class }) |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 46 | @SuppressWarnings({ "rawtypes", "unchecked" }) |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 47 | public class ProxyArpManagerTest { |
Yuta HIGUCHI | 1a1b44f | 2014-06-18 10:56:42 -0700 | [diff] [blame] | 48 | |
| 49 | static { |
| 50 | // configuration to quickly fall back to instance mode for faster test run |
| 51 | System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0"); |
| 52 | } |
| 53 | |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 54 | String defaultStrAgingMsec = "60000"; |
| 55 | String defaultStrCleanupMsec = "60000"; |
| 56 | |
| 57 | ProxyArpManager arpManager; |
| 58 | FloodlightModuleContext context; |
| 59 | IFloodlightProviderService floodligthProviderService; |
| 60 | IConfigInfoService configInfoService; |
| 61 | IRestApiService restApiService; |
| 62 | IDatagridService datagridService; |
| 63 | IFlowPusherService flowPusherService; |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 64 | ITopologyService topologyService; |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 65 | IHostService hostService; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 66 | IPacketService packetService; |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 67 | Map<String, String> configMap; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 68 | |
| 69 | String srcStrMac, dstStrMac, cachedStrMac1, cachedStrMac2, srcStrIp, dstStrIp, cachedStrIp1, cachedStrIp2; |
| 70 | byte[] srcByteMac, dstByteMac; |
| 71 | MACAddress dstMac, srcMac, cachedMac1, cachedMac2; |
| 72 | InetAddress srcIp, dstIp, cachedIp1, cachedIp2; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 73 | Dpid sw1Dpid; |
| 74 | PortNumber sw1Inport, sw1Outport; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 75 | Short vlanId; |
| 76 | ARP arpRequest, arpReply, rarpRequest; |
| 77 | Ethernet ethArpRequest, ethArpReply, ethRarpRequest, ethArpOtherOp; |
| 78 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 79 | Topology topology; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 80 | IEventChannel eg; |
| 81 | IEventChannelListener el; |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 82 | Host host1; |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 83 | Port inPort1, outPort1; |
| 84 | Switch sw1; |
| 85 | ArpCache arpCache; |
| 86 | List<String> arpCacheComparisonList; |
| 87 | |
| 88 | @Before |
| 89 | public void setUp() throws Exception { |
| 90 | makeTestedObject(); |
| 91 | makeMock(); |
| 92 | prepareExpectForInit(); |
| 93 | prepareExpectForStartUp(); |
| 94 | prepareExpectForGeneral(); |
| 95 | } |
| 96 | |
Yuta HIGUCHI | 33a0497 | 2014-06-03 13:00:15 -0700 | [diff] [blame] | 97 | private void makeTestedObject() throws UnknownHostException { |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 98 | //Made tested values |
| 99 | srcStrMac = "00:00:00:00:00:01"; |
| 100 | dstStrMac = "00:00:00:00:00:02"; |
| 101 | cachedStrMac1 = "00:00:00:00:00:03"; |
| 102 | cachedStrMac2 = "00:00:00:00:00:04"; |
| 103 | srcStrIp = "192.168.0.1"; |
| 104 | dstStrIp = "192.168.0.2"; |
| 105 | cachedStrIp1 = "192.168.0.3"; |
| 106 | cachedStrIp2 = "192.168.0.4"; |
| 107 | srcByteMac = Ethernet.toMACAddress(srcStrMac); |
| 108 | dstByteMac = Ethernet.toMACAddress(dstStrMac); |
| 109 | dstMac = new MACAddress(dstByteMac); |
| 110 | srcMac = new MACAddress(srcByteMac); |
| 111 | cachedMac1 = new MACAddress(Ethernet.toMACAddress(cachedStrMac1)); |
| 112 | cachedMac2 = new MACAddress(Ethernet.toMACAddress(cachedStrMac2)); |
Yuta HIGUCHI | 33a0497 | 2014-06-03 13:00:15 -0700 | [diff] [blame] | 113 | |
| 114 | srcIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(srcStrIp)); |
| 115 | dstIp = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(dstStrIp)); |
| 116 | cachedIp1 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp1)); |
| 117 | cachedIp2 = InetAddress.getByAddress(IPv4.toIPv4AddressBytes(cachedStrIp2)); |
| 118 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 119 | sw1Dpid = new Dpid(1L); |
| 120 | sw1Inport = new PortNumber((short) 1); |
| 121 | sw1Outport = new PortNumber((short) 2); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 122 | vlanId = 1; |
| 123 | |
| 124 | //Made tested packets |
| 125 | arpRequest = new ARP() |
| 126 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 127 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 128 | .setHardwareAddressLength((byte) 6) |
| 129 | .setProtocolAddressLength((byte) 4) |
| 130 | .setOpCode(ARP.OP_REQUEST) |
| 131 | .setSenderHardwareAddress(srcByteMac) |
| 132 | .setSenderProtocolAddress(srcIp.getAddress()) |
| 133 | .setTargetProtocolAddress(dstIp.getAddress()) |
| 134 | .setTargetHardwareAddress(dstByteMac); |
| 135 | |
| 136 | ethArpRequest = (Ethernet) new Ethernet() |
| 137 | .setSourceMACAddress(srcStrMac) |
| 138 | .setDestinationMACAddress(dstStrMac) |
| 139 | .setEtherType(Ethernet.TYPE_ARP) |
| 140 | .setVlanID((short) 0) |
| 141 | .setPayload(arpRequest); |
| 142 | |
| 143 | arpReply = new ARP() |
| 144 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 145 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 146 | .setHardwareAddressLength((byte) 6) |
| 147 | .setProtocolAddressLength((byte) 4) |
| 148 | .setOpCode(ARP.OP_RARP_REPLY) |
| 149 | .setSenderHardwareAddress(srcByteMac) |
| 150 | .setSenderProtocolAddress(srcIp.getAddress()) |
| 151 | .setTargetProtocolAddress(dstIp.getAddress()) |
| 152 | .setTargetHardwareAddress(dstByteMac); |
| 153 | |
| 154 | ethArpReply = (Ethernet) new Ethernet() |
| 155 | .setSourceMACAddress(srcStrMac) |
| 156 | .setDestinationMACAddress(dstStrMac) |
| 157 | .setEtherType(Ethernet.TYPE_ARP) |
| 158 | .setVlanID((short) 0) |
| 159 | .setPayload(arpReply); |
| 160 | |
| 161 | rarpRequest = new ARP() |
| 162 | .setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 163 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 164 | .setHardwareAddressLength((byte) 6) |
| 165 | .setProtocolAddressLength((byte) 4) |
| 166 | .setOpCode(ARP.OP_RARP_REQUEST) |
| 167 | .setSenderHardwareAddress(srcByteMac) |
| 168 | .setSenderProtocolAddress(srcIp.getAddress()) |
| 169 | .setTargetProtocolAddress(dstIp.getAddress()) |
| 170 | .setTargetHardwareAddress(dstByteMac); |
| 171 | |
| 172 | ethRarpRequest = (Ethernet) new Ethernet() |
| 173 | .setSourceMACAddress(srcStrMac) |
| 174 | .setDestinationMACAddress(dstStrMac) |
| 175 | .setEtherType(Ethernet.TYPE_RARP) |
| 176 | .setVlanID((short) 0) |
| 177 | .setPayload(rarpRequest); |
| 178 | |
| 179 | ethArpOtherOp = (Ethernet) new Ethernet() |
| 180 | .setSourceMACAddress(srcStrMac) |
| 181 | .setDestinationMACAddress(dstStrMac) |
| 182 | .setEtherType(Ethernet.TYPE_ARP) |
| 183 | .setVlanID((short) 0) |
| 184 | .setPayload(rarpRequest); |
| 185 | |
| 186 | //Made tested objects |
| 187 | arpCache = new ArpCache(); |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 188 | arpCache.setArpEntryTimeoutConfig(Long.parseLong(defaultStrCleanupMsec)); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 189 | arpCache.update(cachedIp1, cachedMac1); |
Yuta HIGUCHI | 238fa2a | 2014-05-01 09:56:46 -0700 | [diff] [blame] | 190 | arpCache.update(cachedIp2, cachedMac2); |
| 191 | |
| 192 | arpCacheComparisonList = new ArrayList<String>(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 193 | arpCacheComparisonList.add(cachedStrIp1 |
| 194 | + " => " |
| 195 | + cachedStrMac1 |
| 196 | + " : VALID"); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 197 | arpCacheComparisonList.add(cachedStrIp2 |
| 198 | + " => " |
| 199 | + cachedStrMac2 |
| 200 | + " : VALID"); |
| 201 | |
| 202 | arpManager = new ProxyArpManager(); |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 203 | configMap = new HashMap<String, String>(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | private void makeMock() { |
| 207 | //Mock floodlight modules |
| 208 | context = EasyMock.createMock(FloodlightModuleContext.class); |
| 209 | floodligthProviderService = EasyMock.createMock(IFloodlightProviderService.class); |
| 210 | configInfoService = EasyMock.createMock(IConfigInfoService.class); |
| 211 | restApiService = EasyMock.createMock(IRestApiService.class); |
| 212 | datagridService = EasyMock.createMock(IDatagridService.class); |
| 213 | flowPusherService = EasyMock.createMock(IFlowPusherService.class); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 214 | topologyService = EasyMock.createMock(ITopologyService.class); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 215 | hostService = EasyMock.createMock(IHostService.class); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 216 | packetService = EasyMock.createMock(IPacketService.class); |
| 217 | eg = EasyMock.createMock(IEventChannel.class); |
| 218 | el = EasyMock.createMock(IEventChannelListener.class); |
| 219 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 220 | //Mock Topology related data |
| 221 | topology = EasyMock.createMock(Topology.class); |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 222 | host1 = EasyMock.createMock(Host.class); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 223 | inPort1 = EasyMock.createMock(Port.class); |
| 224 | outPort1 = EasyMock.createMock(Port.class); |
| 225 | sw1 = EasyMock.createMock(Switch.class); |
| 226 | } |
| 227 | |
| 228 | private void prepareExpectForGeneral() { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 229 | EasyMock.expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes(); |
| 230 | EasyMock.expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 231 | EasyMock.expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes(); |
| 232 | EasyMock.expect(outPort1.getIncomingLink()).andReturn(null).anyTimes(); |
| 233 | EasyMock.expect(outPort1.getSwitch()).andReturn(sw1).anyTimes(); |
| 234 | EasyMock.expect(sw1.getDpid()).andReturn(sw1Dpid).anyTimes(); |
| 235 | } |
| 236 | |
| 237 | private void prepareExpectForInit() { |
| 238 | EasyMock.expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodligthProviderService); |
| 239 | EasyMock.expect(context.getServiceImpl(IConfigInfoService.class)).andReturn(configInfoService); |
| 240 | EasyMock.expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApiService); |
| 241 | EasyMock.expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService); |
| 242 | EasyMock.expect(context.getServiceImpl(IFlowPusherService.class)).andReturn(flowPusherService); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 243 | EasyMock.expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService); |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 244 | EasyMock.expect(context.getServiceImpl(IHostService.class)).andReturn(hostService); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 245 | EasyMock.expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService); |
| 246 | } |
| 247 | |
| 248 | private void prepareExpectForStartUp() { |
Yuta HIGUCHI | 33a0497 | 2014-06-03 13:00:15 -0700 | [diff] [blame] | 249 | // XXX Commented out as workaround for PowerMock + Hazelcast issue. |
| 250 | // try { |
| 251 | // PowerMock.expectNew(ArpCache.class).andReturn(arpCache); |
| 252 | // } catch (Exception e) { |
| 253 | // fail("Exception:" + e.getMessage()); |
| 254 | // } |
| 255 | // PowerMock.replayAll(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 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, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 286 | topologyService, hostService, packetService, topology, eg, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 287 | el, host1, 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, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 305 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 306 | eg, el, host1, 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, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 323 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 324 | eg, el, host1, 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, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 338 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 339 | eg, el, host1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 340 | arpManager.init(context); |
| 341 | arpManager.startUp(context); |
Yuta HIGUCHI | 33a0497 | 2014-06-03 13:00:15 -0700 | [diff] [blame] | 342 | |
| 343 | // XXX workaround for PowerMock + Hazelcast issue. |
| 344 | this.arpManager.debugReplaceArpCache(arpCache); |
| 345 | |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 346 | MACAddress mac = arpManager.getMacAddress(cachedIp1); |
| 347 | assertEquals(cachedMac1, mac); |
| 348 | } |
| 349 | |
| 350 | @Test |
| 351 | public void testGetMappings() { |
| 352 | Map<String, String> config = new HashMap<String, String>(); |
| 353 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 354 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 355 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 356 | restApiService, datagridService, flowPusherService, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 357 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 358 | eg, el, host1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 359 | arpManager.init(context); |
| 360 | arpManager.startUp(context); |
| 361 | List<String> list = arpManager.getMappings(); |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 362 | for (String str : list) { |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 363 | assertTrue(arpCacheComparisonList.contains(str)); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | @Test |
| 368 | public void testReceivePacketWithNoArpPacket() { |
| 369 | Map<String, String> config = new HashMap<String, String>(); |
| 370 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 371 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 372 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 373 | restApiService, datagridService, flowPusherService, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 374 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 375 | eg, el, host1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 376 | arpManager.init(context); |
| 377 | arpManager.startUp(context); |
| 378 | arpManager.receive(sw1, inPort1, ethRarpRequest); |
| 379 | } |
| 380 | |
| 381 | @Test |
| 382 | public void testReceivePacketWithOtherOpCode() { |
| 383 | Map<String, String> config = new HashMap<String, String>(); |
| 384 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 385 | |
| 386 | prepareExpectForLearnArp(); |
| 387 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 388 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 389 | restApiService, datagridService, flowPusherService, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 390 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 391 | eg, el, host1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 392 | arpManager.init(context); |
| 393 | arpManager.startUp(context); |
| 394 | arpManager.receive(sw1, inPort1, ethArpOtherOp); |
| 395 | } |
| 396 | |
| 397 | @Test |
| 398 | public void testClassifyPacketToSendArpReplyNotification() { |
| 399 | Map<String, String> config = new HashMap<String, String>(); |
| 400 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 401 | |
| 402 | prepareExpectForLearnArp(); |
| 403 | |
| 404 | ArpReplyNotification value = |
| 405 | new ArpReplyNotification(ByteBuffer.wrap(dstIp.getAddress()).getInt(), dstMac); |
| 406 | eg.addTransientEntry(srcMac.toLong(), value); |
| 407 | EasyMock.expectLastCall(); |
| 408 | EasyMock.expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService); |
| 409 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 410 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 411 | restApiService, datagridService, flowPusherService, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 412 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 413 | eg, el, host1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 414 | arpManager.init(context); |
| 415 | arpManager.startUp(context); |
| 416 | arpManager.receive(sw1, inPort1, ethArpReply); |
| 417 | } |
| 418 | |
| 419 | @Test |
| 420 | public void testClassifyPacketToHandleArpRequest() { |
| 421 | Map<String, String> config = new HashMap<String, String>(); |
| 422 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 423 | |
| 424 | prepareExpectForLearnArp(); |
| 425 | |
| 426 | EasyMock.expect(configInfoService.fromExternalNetwork(EasyMock.anyLong(), EasyMock.anyShort())).andReturn(true); |
| 427 | EasyMock.expect(configInfoService.isInterfaceAddress(dstIp)).andReturn(false); |
| 428 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 429 | EasyMock.replay(context, floodligthProviderService, configInfoService, |
| 430 | restApiService, datagridService, flowPusherService, |
Jonathan Hart | 0310213 | 2014-07-01 23:22:04 -0700 | [diff] [blame] | 431 | topologyService, hostService, packetService, topology, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 432 | eg, el, host1, inPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 433 | arpManager.init(context); |
| 434 | arpManager.startUp(context); |
| 435 | arpManager.receive(sw1, inPort1, ethArpRequest); |
| 436 | } |
| 437 | |
| 438 | @Test |
| 439 | public void testClassifyPacketToHandleArpRequest2() { |
| 440 | List<Port> portList = new ArrayList<Port>(); |
| 441 | portList.add(outPort1); |
| 442 | |
| 443 | Map<String, String> config = new HashMap<String, String>(); |
| 444 | EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config); |
| 445 | |
| 446 | prepareExpectForLearnArp(); |
| 447 | |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 448 | EasyMock.expect(configInfoService.fromExternalNetwork( |
| 449 | EasyMock.anyLong(), EasyMock.anyShort())).andReturn(false); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 450 | topology.acquireReadLock(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 451 | EasyMock.expectLastCall(); |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 452 | EasyMock.expect(topology.getHostByMac(dstMac)).andReturn(host1); |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 453 | topology.releaseReadLock(); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 454 | EasyMock.expectLastCall(); |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 455 | EasyMock.expect(host1.getAttachmentPoints()).andReturn(portList); |
Yuta HIGUCHI | 44a0b35 | 2014-05-14 21:32:48 -0700 | [diff] [blame] | 456 | eg.addTransientEntry(EasyMock.anyLong(), EasyMock.anyObject()); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 457 | EasyMock.expectLastCall(); |
| 458 | |
| 459 | EasyMock.replay(context, configInfoService, restApiService, floodligthProviderService, |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 460 | topologyService, datagridService, eg, topology, host1, inPort1, outPort1, sw1); |
TeruU | 8b2d167 | 2014-04-25 17:02:56 -0700 | [diff] [blame] | 461 | arpManager.init(context); |
| 462 | arpManager.startUp(context); |
| 463 | arpManager.receive(sw1, inPort1, ethArpRequest); |
| 464 | } |
| 465 | } |