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