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