blob: ee70f32cb0bbf33710e906a9a3811ae6e9dc48d9 [file] [log] [blame]
TeruU8b2d1672014-04-25 17:02:56 -07001package net.onrc.onos.apps.proxyarp;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -07005
TeruU8b2d1672014-04-25 17:02:56 -07006import java.net.InetAddress;
7import java.net.UnknownHostException;
8import java.nio.ByteBuffer;
9import java.util.ArrayList;
10import java.util.HashMap;
11import java.util.List;
12import java.util.Map;
13
TeruU8b2d1672014-04-25 17:02:56 -070014import net.floodlightcontroller.core.IFloodlightProviderService;
15import net.floodlightcontroller.core.module.FloodlightModuleContext;
16import net.floodlightcontroller.restserver.IRestApiService;
17import net.floodlightcontroller.util.MACAddress;
18import net.onrc.onos.api.packet.IPacketService;
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -070019import net.onrc.onos.apps.proxyarp.web.ArpWebRoutable;
TeruU8b2d1672014-04-25 17:02:56 -070020import net.onrc.onos.core.datagrid.IDatagridService;
21import net.onrc.onos.core.datagrid.IEventChannel;
22import net.onrc.onos.core.datagrid.IEventChannelListener;
TeruU8b2d1672014-04-25 17:02:56 -070023import net.onrc.onos.core.flowprogrammer.IFlowPusherService;
Jonathan Hart03102132014-07-01 23:22:04 -070024import net.onrc.onos.core.hostmanager.IHostService;
TeruU8b2d1672014-04-25 17:02:56 -070025import net.onrc.onos.core.main.config.IConfigInfoService;
26import net.onrc.onos.core.packet.ARP;
27import net.onrc.onos.core.packet.Ethernet;
28import net.onrc.onos.core.packet.IPv4;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070029import net.onrc.onos.core.topology.Host;
Jonathan Harte37e4e22014-05-13 19:12:02 -070030import net.onrc.onos.core.topology.ITopologyService;
31import net.onrc.onos.core.topology.Topology;
TeruU8b2d1672014-04-25 17:02:56 -070032import net.onrc.onos.core.topology.Port;
33import net.onrc.onos.core.topology.Switch;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070034import net.onrc.onos.core.util.Dpid;
35import net.onrc.onos.core.util.PortNumber;
TeruU8b2d1672014-04-25 17:02:56 -070036
37import org.easymock.EasyMock;
38import org.junit.After;
39import org.junit.Before;
40import org.junit.Test;
TeruU8b2d1672014-04-25 17:02:56 -070041
Yuta HIGUCHI33a04972014-06-03 13:00:15 -070042// 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 Milkeyff735142014-05-22 19:06:02 -070046@SuppressWarnings({ "rawtypes", "unchecked" })
TeruU8b2d1672014-04-25 17:02:56 -070047public class ProxyArpManagerTest {
Yuta HIGUCHI1a1b44f2014-06-18 10:56:42 -070048
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
TeruU8b2d1672014-04-25 17:02:56 -070054 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 Harte37e4e22014-05-13 19:12:02 -070064 ITopologyService topologyService;
Jonathan Hart03102132014-07-01 23:22:04 -070065 IHostService hostService;
TeruU8b2d1672014-04-25 17:02:56 -070066 IPacketService packetService;
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070067 Map<String, String> configMap;
TeruU8b2d1672014-04-25 17:02:56 -070068
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 HIGUCHI8f3dfa32014-06-25 00:14:25 -070073 Dpid sw1Dpid;
74 PortNumber sw1Inport, sw1Outport;
TeruU8b2d1672014-04-25 17:02:56 -070075 Short vlanId;
76 ARP arpRequest, arpReply, rarpRequest;
77 Ethernet ethArpRequest, ethArpReply, ethRarpRequest, ethArpOtherOp;
78
Jonathan Harte37e4e22014-05-13 19:12:02 -070079 Topology topology;
TeruU8b2d1672014-04-25 17:02:56 -070080 IEventChannel eg;
81 IEventChannelListener el;
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070082 Host host1;
TeruU8b2d1672014-04-25 17:02:56 -070083 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 HIGUCHI33a04972014-06-03 13:00:15 -070097 private void makeTestedObject() throws UnknownHostException {
TeruU8b2d1672014-04-25 17:02:56 -070098 //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 HIGUCHI33a04972014-06-03 13:00:15 -0700113
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 HIGUCHI8f3dfa32014-06-25 00:14:25 -0700119 sw1Dpid = new Dpid(1L);
120 sw1Inport = new PortNumber((short) 1);
121 sw1Outport = new PortNumber((short) 2);
TeruU8b2d1672014-04-25 17:02:56 -0700122 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 HIGUCHI238fa2a2014-05-01 09:56:46 -0700188 arpCache.setArpEntryTimeoutConfig(Long.parseLong(defaultStrCleanupMsec));
TeruU8b2d1672014-04-25 17:02:56 -0700189 arpCache.update(cachedIp1, cachedMac1);
Yuta HIGUCHI238fa2a2014-05-01 09:56:46 -0700190 arpCache.update(cachedIp2, cachedMac2);
191
192 arpCacheComparisonList = new ArrayList<String>();
TeruU8b2d1672014-04-25 17:02:56 -0700193 arpCacheComparisonList.add(cachedStrIp1
194 + " => "
195 + cachedStrMac1
196 + " : VALID");
TeruU8b2d1672014-04-25 17:02:56 -0700197 arpCacheComparisonList.add(cachedStrIp2
198 + " => "
199 + cachedStrMac2
200 + " : VALID");
201
202 arpManager = new ProxyArpManager();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700203 configMap = new HashMap<String, String>();
TeruU8b2d1672014-04-25 17:02:56 -0700204 }
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 Harte37e4e22014-05-13 19:12:02 -0700214 topologyService = EasyMock.createMock(ITopologyService.class);
Jonathan Hart03102132014-07-01 23:22:04 -0700215 hostService = EasyMock.createMock(IHostService.class);
TeruU8b2d1672014-04-25 17:02:56 -0700216 packetService = EasyMock.createMock(IPacketService.class);
217 eg = EasyMock.createMock(IEventChannel.class);
218 el = EasyMock.createMock(IEventChannelListener.class);
219
Jonathan Harte37e4e22014-05-13 19:12:02 -0700220 //Mock Topology related data
221 topology = EasyMock.createMock(Topology.class);
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700222 host1 = EasyMock.createMock(Host.class);
TeruU8b2d1672014-04-25 17:02:56 -0700223 inPort1 = EasyMock.createMock(Port.class);
224 outPort1 = EasyMock.createMock(Port.class);
225 sw1 = EasyMock.createMock(Switch.class);
226 }
227
228 private void prepareExpectForGeneral() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -0700229 EasyMock.expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes();
230 EasyMock.expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes();
TeruU8b2d1672014-04-25 17:02:56 -0700231 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 Harte37e4e22014-05-13 19:12:02 -0700243 EasyMock.expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService);
Jonathan Hart03102132014-07-01 23:22:04 -0700244 EasyMock.expect(context.getServiceImpl(IHostService.class)).andReturn(hostService);
TeruU8b2d1672014-04-25 17:02:56 -0700245 EasyMock.expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService);
246 }
247
248 private void prepareExpectForStartUp() {
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700249 // 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();
TeruU8b2d1672014-04-25 17:02:56 -0700256 EasyMock.expect(configInfoService.getVlan()).andReturn(vlanId);
257 restApiService.addRestletRoutable(EasyMock.isA(ArpWebRoutable.class));
258 EasyMock.expectLastCall();
259 packetService.registerPacketListener(arpManager);
260 EasyMock.expectLastCall();
Jonathan Harte37e4e22014-05-13 19:12:02 -0700261 EasyMock.expect(topologyService.getTopology()).andReturn(topology);
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700262 EasyMock.expect(datagridService.addListener(EasyMock.<String>anyObject(),
263 EasyMock.isA(IEventChannelListener.class),
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700264 (Class) EasyMock.anyObject(), (Class) EasyMock.anyObject())).andReturn(eg).anyTimes();
TeruU8b2d1672014-04-25 17:02:56 -0700265 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 HIGUCHI238fa2a2014-05-01 09:56:46 -0700276 arpCache = null;
TeruU8b2d1672014-04-25 17:02:56 -0700277 }
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 HIGUCHI91a8f502014-06-17 10:15:29 -0700284 EasyMock.replay(context, floodligthProviderService, configInfoService,
285 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700286 topologyService, hostService, packetService, topology, eg,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700287 el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700288 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700303 EasyMock.replay(context, floodligthProviderService, configInfoService,
304 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700305 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700306 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700307 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 HIGUCHI44a0b352014-05-14 21:32:48 -0700317 configMap.put("agingmsec", strAgingMsec);
318 configMap.put("cleanupmsec", strCleanupMsec);
319 EasyMock.expect(context.getConfigParams(arpManager)).andReturn(configMap);
TeruU8b2d1672014-04-25 17:02:56 -0700320
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -0700321 EasyMock.replay(context, floodligthProviderService, configInfoService,
322 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700323 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700324 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700325 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700336 EasyMock.replay(context, floodligthProviderService, configInfoService,
337 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700338 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700339 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700340 arpManager.init(context);
341 arpManager.startUp(context);
Yuta HIGUCHI33a04972014-06-03 13:00:15 -0700342
343 // XXX workaround for PowerMock + Hazelcast issue.
344 this.arpManager.debugReplaceArpCache(arpCache);
345
TeruU8b2d1672014-04-25 17:02:56 -0700346 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700355 EasyMock.replay(context, floodligthProviderService, configInfoService,
356 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700357 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700358 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700359 arpManager.init(context);
360 arpManager.startUp(context);
361 List<String> list = arpManager.getMappings();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700362 for (String str : list) {
TeruU8b2d1672014-04-25 17:02:56 -0700363 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700372 EasyMock.replay(context, floodligthProviderService, configInfoService,
373 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700374 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700375 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700376 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700388 EasyMock.replay(context, floodligthProviderService, configInfoService,
389 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700390 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700391 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700392 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700410 EasyMock.replay(context, floodligthProviderService, configInfoService,
411 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700412 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700413 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700414 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700429 EasyMock.replay(context, floodligthProviderService, configInfoService,
430 restApiService, datagridService, flowPusherService,
Jonathan Hart03102132014-07-01 23:22:04 -0700431 topologyService, hostService, packetService, topology,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700432 eg, el, host1, inPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700433 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 HIGUCHI91a8f502014-06-17 10:15:29 -0700448 EasyMock.expect(configInfoService.fromExternalNetwork(
449 EasyMock.anyLong(), EasyMock.anyShort())).andReturn(false);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700450 topology.acquireReadLock();
TeruU8b2d1672014-04-25 17:02:56 -0700451 EasyMock.expectLastCall();
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700452 EasyMock.expect(topology.getHostByMac(dstMac)).andReturn(host1);
Jonathan Harte37e4e22014-05-13 19:12:02 -0700453 topology.releaseReadLock();
TeruU8b2d1672014-04-25 17:02:56 -0700454 EasyMock.expectLastCall();
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700455 EasyMock.expect(host1.getAttachmentPoints()).andReturn(portList);
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700456 eg.addTransientEntry(EasyMock.anyLong(), EasyMock.anyObject());
TeruU8b2d1672014-04-25 17:02:56 -0700457 EasyMock.expectLastCall();
458
459 EasyMock.replay(context, configInfoService, restApiService, floodligthProviderService,
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -0700460 topologyService, datagridService, eg, topology, host1, inPort1, outPort1, sw1);
TeruU8b2d1672014-04-25 17:02:56 -0700461 arpManager.init(context);
462 arpManager.startUp(context);
463 arpManager.receive(sw1, inPort1, ethArpRequest);
464 }
465}