54c18b16482a06837c672381f7d92aa91d59a174
[netvirt.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / impl / NeutronL3AdapterTest.java
1 /*
2  * Copyright (c) 2015 Inocybe and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.openstack.netvirt.impl;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.anyBoolean;
14 import static org.mockito.Matchers.anyInt;
15 import static org.mockito.Matchers.anyLong;
16 import static org.mockito.Matchers.anyString;
17 import static org.mockito.Matchers.eq;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.times;
20 import static org.mockito.Mockito.when;
21
22 import java.lang.reflect.Constructor;
23 import java.lang.reflect.Field;
24 import java.net.InetAddress;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import org.apache.commons.lang3.tuple.Pair;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronFloatingIP;
39 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
40 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronPort;
41 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronRouter;
42 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronRouter_Interface;
43 import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSubnet;
44 import org.opendaylight.ovsdb.openstack.netvirt.translator.Neutron_IPs;
45 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronNetworkCRUD;
46 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronPortCRUD;
47 import org.opendaylight.ovsdb.openstack.netvirt.translator.crud.INeutronSubnetCRUD;
48 import org.opendaylight.ovsdb.openstack.netvirt.AbstractHandler;
49 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
50 import org.opendaylight.ovsdb.openstack.netvirt.api.ArpProvider;
51 import org.opendaylight.ovsdb.openstack.netvirt.api.ConfigurationService;
52 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
53 import org.opendaylight.ovsdb.openstack.netvirt.api.InboundNatProvider;
54 import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
55 import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
56 import org.opendaylight.ovsdb.openstack.netvirt.api.OutboundNatProvider;
57 import org.opendaylight.ovsdb.openstack.netvirt.api.RoutingProvider;
58 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
59 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
60 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
61 import org.opendaylight.ovsdb.openstack.netvirt.api.TenantNetworkManager;
62 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
68
69 import org.osgi.framework.ServiceReference;
70 import org.powermock.api.mockito.PowerMockito;
71 import org.powermock.api.support.membermodification.MemberMatcher;
72 import org.powermock.api.support.membermodification.MemberModifier;
73 import org.powermock.core.classloader.annotations.PrepareForTest;
74 import org.powermock.modules.junit4.PowerMockRunner;
75 import org.powermock.reflect.Whitebox;
76
77 /**
78  * Unit test for {@link NeutronL3Adapter}
79  */
80 @PrepareForTest({ServiceHelper.class, InetAddress.class, NeutronL3Adapter.class})
81 @RunWith(PowerMockRunner.class)
82 public class NeutronL3AdapterTest {
83
84     @Mock private NeutronL3Adapter neutronL3Adapter;
85
86     private static final String ID = "45";
87     private static final String IP = "127.0.0.1";
88     private static final String MALFORM_IP = "127.0.0.1.5";
89     private static final String INTF_NAME = "br-int";
90     private static final String EXTERNAL_ROUTER_MAC_UPDATE = "";
91     private static final String UUID = "7da709ff-397f-4778-a0e8-994811272fdb";
92     private static final String FIXED_IP_ADDRESS = "192.168.1.0";
93     private static final String FLOATING_IP_ADDRESS = "192.168.1.1";
94     private static final String OWNER_ROUTER_INTERFACE = "network:router_interface";
95     private static final String OWNER_FLOATING_IP = "network:floatingip";
96     private static final String MAC_ADDRESS = "00:00:5E:00:02:01";
97     private static final String MAC_ADDRESS_2 = "00:00:5E:00:02:02";
98     private static final String PORT_INT = "port_int";
99     private static final String SEG_ID = "2";
100     private static final String CIDR = "192.168.100.0/24";
101     private static final String OFPort = "OFPort|45";
102     private static final String IP_MASK = "127.0.0.1/32";
103
104     @SuppressWarnings("rawtypes")
105     private Class floatingIpClass;
106     private Object floatingIpObject;
107
108     @Before
109     public void setUp() throws Exception{
110         neutronL3Adapter = PowerMockito.mock(NeutronL3Adapter.class, Mockito.CALLS_REAL_METHODS);
111
112         // init instance variables
113         MemberModifier.field(NeutronL3Adapter.class, "enabled").set(neutronL3Adapter, true);
114
115         // floating ip (nested private class from NeutronL3Adapter)
116         floatingIpClass = Whitebox.getInnerClassType(NeutronL3Adapter.class, "FloatIpData");
117         floatingIpObject = createFloatingIpObject();
118     }
119
120     @Test
121     public void testUpdateExternalRouterMac() throws Exception {
122         // Suppress the called to these functions
123         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "flushExistingIpRewrite"));
124         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "rebuildExistingIpRewrite"));
125
126         neutronL3Adapter.updateExternalRouterMac(EXTERNAL_ROUTER_MAC_UPDATE);
127
128         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("flushExistingIpRewrite");
129         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("rebuildExistingIpRewrite");
130     }
131
132     @Test
133     public void testhandleNeutronSubnetEvent() throws Exception {
134         // Nothing to be done here
135         neutronL3Adapter.handleNeutronSubnetEvent(mock(NeutronSubnet.class), Action.ADD);
136     }
137
138     @Test
139     public void testHandleNeutronPortEvent() throws Exception {
140         Map<String, NeutronRouter_Interface> subnetIdToRouterInterfaceCache = new HashMap<>();
141         // Mock variables
142         Neutron_IPs neutronIP = mock(Neutron_IPs.class);
143         when(neutronIP.getSubnetUUID()).thenReturn(UUID);
144         List<Neutron_IPs> list_neutronIP = new ArrayList<>();
145         list_neutronIP.add(neutronIP);
146         NeutronPort neutronPort = mock(NeutronPort.class);
147         when(neutronPort.getDeviceOwner()).thenReturn(OWNER_ROUTER_INTERFACE);
148         when(neutronPort.getFixedIPs()).thenReturn(list_neutronIP);
149
150         // init instance variables
151         MemberModifier.field(NeutronL3Adapter.class, "neutronPortCache").set(neutronL3Adapter , mock(INeutronPortCRUD.class));
152         subnetIdToRouterInterfaceCache.put(UUID, mock(NeutronRouter_Interface.class));
153         MemberModifier.field(NeutronL3Adapter.class, "subnetIdToRouterInterfaceCache").set(neutronL3Adapter , subnetIdToRouterInterfaceCache);
154
155         // Suppress the called to these functions
156         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "updateL3ForNeutronPort", NeutronPort.class, boolean.class));
157         Mockito.doNothing().when(neutronL3Adapter).handleNeutronRouterInterfaceEvent(any(NeutronRouter.class), any(NeutronRouter_Interface.class), any(Action.class));
158
159         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
160         Mockito.verify(neutronL3Adapter).handleNeutronRouterInterfaceEvent(any(NeutronRouter.class), any(NeutronRouter_Interface.class), eq(Action.ADD));
161
162         when(neutronPort.getDeviceOwner()).thenReturn("");
163         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.ADD);
164         Mockito.verify(neutronL3Adapter, times(2)).handleNeutronRouterInterfaceEvent(any(NeutronRouter.class), any(NeutronRouter_Interface.class), eq(Action.ADD));
165         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("updateL3ForNeutronPort", any(NeutronPort.class), eq(false));
166
167         neutronL3Adapter.handleNeutronPortEvent(neutronPort, Action.DELETE);
168         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("updateL3ForNeutronPort", any(NeutronPort.class), eq(true));
169     }
170
171     @Test
172     public void testhandleNeutronRouterEvent() throws Exception {
173         // Nothing to be done here
174         neutronL3Adapter.handleNeutronRouterEvent(mock(NeutronRouter.class), Action.ADD);
175     }
176
177     @Test
178     public void testHandleNeutronRouterInterfaceEvent() throws Exception {
179         // Mock variables
180         NeutronRouter_Interface neutronRouterInterface = mock(NeutronRouter_Interface.class);
181         when(neutronRouterInterface.getPortUUID()).thenReturn(UUID);
182         when(neutronRouterInterface.getSubnetUUID()).thenReturn(UUID);
183
184         Neutron_IPs neutronIP = mock(Neutron_IPs.class);
185         when(neutronIP.getSubnetUUID()).thenReturn(UUID);
186         NeutronPort neutronPort = mock(NeutronPort.class);
187         List<Neutron_IPs> list_neutronIP = new ArrayList<>();
188         list_neutronIP.add(neutronIP);
189         when(neutronPort.getFixedIPs()).thenReturn(list_neutronIP);
190         List<NeutronPort> list_neutronPort = new ArrayList<>();
191         list_neutronPort.add(neutronPort);
192         INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
193         when(neutronPortCache.getAllPorts()).thenReturn(list_neutronPort);
194
195         // init instance variables
196         MemberModifier.field(NeutronL3Adapter.class, "neutronPortCache").set(neutronL3Adapter , neutronPortCache);
197
198         // Suppress the called to these functions
199         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowsForNeutronRouterInterface", NeutronRouter_Interface.class, Boolean.class));
200         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "updateL3ForNeutronPort", NeutronPort.class, boolean.class));
201
202         neutronL3Adapter.handleNeutronRouterInterfaceEvent(mock(NeutronRouter.class), neutronRouterInterface, Action.ADD);
203         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForNeutronRouterInterface", any(NeutronRouter_Interface.class), eq(false));
204         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("updateL3ForNeutronPort", any(NeutronPort.class), eq(false));
205
206         neutronL3Adapter.handleNeutronRouterInterfaceEvent(mock(NeutronRouter.class), neutronRouterInterface, Action.DELETE);
207         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForNeutronRouterInterface", any(NeutronRouter_Interface.class), eq(true));
208         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("updateL3ForNeutronPort", any(NeutronPort.class), eq(true));
209     }
210
211     @Test
212     public void testHandleNeutronFloatingIPEvent() throws Exception {
213         // Mock variables
214         NeutronFloatingIP neutronFloatingIP = mock(NeutronFloatingIP.class);
215         when(neutronFloatingIP.getFixedIPAddress()).thenReturn(FIXED_IP_ADDRESS);
216         when(neutronFloatingIP.getFloatingIPAddress()).thenReturn(FLOATING_IP_ADDRESS);
217         when(neutronFloatingIP.getID()).thenReturn(UUID);
218
219         // Suppress the called to these functions
220         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowsForFloatingIPArpAdd", NeutronFloatingIP.class));
221         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowsForFloatingIPInbound", NeutronFloatingIP.class, Action.class));
222         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowsForFloatingIPOutbound", NeutronFloatingIP.class, Action.class));
223         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowsForFloatingIPArpDelete", String.class));
224
225         neutronL3Adapter.handleNeutronFloatingIPEvent(neutronFloatingIP, Action.ADD);
226         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForFloatingIPArpAdd", any(NeutronFloatingIP.class));
227         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForFloatingIPInbound", any(NeutronFloatingIP.class), eq(Action.ADD));
228         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForFloatingIPOutbound", any(NeutronFloatingIP.class), eq(Action.ADD));
229
230         neutronL3Adapter.handleNeutronFloatingIPEvent(neutronFloatingIP, Action.DELETE);
231         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForFloatingIPArpDelete", anyString());
232         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForFloatingIPInbound", any(NeutronFloatingIP.class), eq(Action.DELETE));
233         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForFloatingIPOutbound", any(NeutronFloatingIP.class), eq(Action.DELETE));
234     }
235
236     @SuppressWarnings({ "unchecked", "rawtypes" })
237     @Test
238     public void testProgramFlowsForFloatingIPInbound() throws Exception {
239         Map floatIpDataMapCache = new HashMap();
240
241         NeutronFloatingIP neutronFloatingIp = mock(NeutronFloatingIP.class);
242         when(neutronFloatingIp.getID()).thenReturn(ID);
243
244         // init instance variables
245         floatIpDataMapCache .put(ID, floatingIpObject);
246         MemberModifier.field(NeutronL3Adapter.class, "floatIpDataMapCache").set(neutronL3Adapter , floatIpDataMapCache);
247
248         // Suppress the called to these functions
249         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programInboundIpRewriteStage1", Long.class, Long.class, String.class, String.class, String.class, Action.class));
250
251         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForFloatingIPInbound", neutronFloatingIp, Action.ADD);
252         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programInboundIpRewriteStage1", anyLong(), anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
253     }
254
255     @SuppressWarnings({ "unchecked", "rawtypes" })
256     @Test
257     public void testProgramFlowsForFloatingIPOutbound() throws Exception {
258         Map floatIpDataMapCache = new HashMap();
259
260         NeutronFloatingIP neutronFloatingIp = mock(NeutronFloatingIP.class);
261         when(neutronFloatingIp.getID()).thenReturn(ID);
262
263         // init instance variables
264         floatIpDataMapCache.put(ID, floatingIpObject);
265         MemberModifier.field(NeutronL3Adapter.class, "floatIpDataMapCache").set(neutronL3Adapter , floatIpDataMapCache);
266
267         // Suppress the called to these functions
268         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programOutboundIpRewriteStage1", floatingIpClass, Action.class));
269
270         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForFloatingIPOutbound", neutronFloatingIp, Action.ADD);
271         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programOutboundIpRewriteStage1", any(floatingIpClass), eq(Action.ADD));
272     }
273
274     @SuppressWarnings({ "unchecked", "rawtypes" })
275     @Test
276     public void testFlushExistingIpRewrite() throws Exception {
277         Map floatIpDataMapCache = new HashMap();
278
279         // init instance variables
280         floatIpDataMapCache.put(ID, floatingIpObject);
281         MemberModifier.field(NeutronL3Adapter.class, "floatIpDataMapCache").set(neutronL3Adapter , floatIpDataMapCache);
282
283         // Suppress the called to these functions
284         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programOutboundIpRewriteStage1", floatingIpClass, Action.class));
285         PowerMockito.doReturn(floatIpDataMapCache.values()).when(neutronL3Adapter, "getAllFloatingIPsWithMetadata");
286         Whitebox.invokeMethod(neutronL3Adapter, "flushExistingIpRewrite");
287         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programOutboundIpRewriteStage1", any(floatingIpClass), eq(Action.DELETE));
288     }
289
290     @SuppressWarnings({ "unchecked", "rawtypes" })
291     @Test
292     public void testRebuildExistingIpRewrite() throws Exception {
293         Map floatIpDataMapCache = new HashMap();
294
295         // init instance variables
296         floatIpDataMapCache.put(ID, floatingIpObject);
297         MemberModifier.field(NeutronL3Adapter.class, "floatIpDataMapCache").set(neutronL3Adapter , floatIpDataMapCache);
298
299         // Suppress the called to these functions
300         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programOutboundIpRewriteStage1", floatingIpClass, Action.class));
301
302         PowerMockito.doReturn(floatIpDataMapCache.values()).when(neutronL3Adapter, "getAllFloatingIPsWithMetadata");
303         Whitebox.invokeMethod(neutronL3Adapter, "rebuildExistingIpRewrite");
304         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programOutboundIpRewriteStage1", any(floatingIpClass), eq(Action.ADD));
305     }
306
307     @SuppressWarnings({ "unchecked", "rawtypes" })
308     @Test
309     public void testProgramFlowsForFloatingIPArpAdd() throws Exception {
310         Map<String, Pair> neutronPortToDpIdCache = new HashMap<>();
311         Map<String, String> networkIdToRouterMacCache = new HashMap<>();
312         Map floatIpDataMapCache = new HashMap();
313
314         NeutronFloatingIP neutronFloatingIP = mock(NeutronFloatingIP.class);
315         when(neutronFloatingIP.getFixedIPAddress()).thenReturn(FIXED_IP_ADDRESS);
316         when(neutronFloatingIP.getFloatingIPAddress()).thenReturn(FLOATING_IP_ADDRESS);
317         when(neutronFloatingIP.getPortUUID()).thenReturn(UUID);
318         NeutronPort neutronPort = mock(NeutronPort.class);
319         when(neutronPort.getMacAddress()).thenReturn(MAC_ADDRESS);
320         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
321         when(neutronNetwork.getProviderSegmentationID()).thenReturn(ID);
322         when(neutronNetwork.getID()).thenReturn(ID);
323
324         // init instance variables
325         floatIpDataMapCache.put(ID, floatingIpObject);
326         neutronPortToDpIdCache.put(UUID, mock(Pair.class));
327         networkIdToRouterMacCache.put(ID, MAC_ADDRESS);
328         INeutronNetworkCRUD neutronNetworkCache = mock(INeutronNetworkCRUD.class);
329         when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
330         INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
331         when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
332         PowerMockito.doReturn(neutronPort).when(neutronL3Adapter, "findNeutronPortForFloatingIp", anyString());
333         PowerMockito.doReturn(15L).when(neutronL3Adapter, "findOFPortForExtPatch", anyLong());
334         MemberModifier.field(NeutronL3Adapter.class, "floatIpDataMapCache").set(neutronL3Adapter , floatIpDataMapCache);
335         MemberModifier.field(NeutronL3Adapter.class, "neutronPortToDpIdCache").set(neutronL3Adapter , neutronPortToDpIdCache);
336         MemberModifier.field(NeutronL3Adapter.class, "neutronPortCache").set(neutronL3Adapter , neutronPortCache);
337         MemberModifier.field(NeutronL3Adapter.class, "neutronNetworkCache").set(neutronL3Adapter , neutronNetworkCache);
338         MemberModifier.field(NeutronL3Adapter.class, "networkIdToRouterMacCache").set(neutronL3Adapter , networkIdToRouterMacCache);
339
340         // Suppress the called to these functions
341         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "findNeutronPortForFloatingIp", String.class));
342         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "findOFPortForExtPatch", Long.class));
343         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programStaticArpStage1", Long.class, String.class, String.class, String.class, Action.class));
344
345         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForFloatingIPArpAdd", neutronFloatingIP);
346         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("findNeutronPortForFloatingIp", anyString());
347         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("findOFPortForExtPatch", anyLong());
348         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage1", anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
349     }
350
351     @SuppressWarnings({ "unchecked", "rawtypes" })
352     @Test
353     public void testProgramFlowsForFloatingIPArpDelete() throws Exception {
354         Map floatIpDataMapCache = new HashMap();
355
356      // init instance variables
357         floatIpDataMapCache.put(ID, floatingIpObject);
358         MemberModifier.field(NeutronL3Adapter.class, "floatIpDataMapCache").set(neutronL3Adapter , floatIpDataMapCache);
359
360         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programStaticArpStage1", Long.class, String.class, String.class, String.class, Action.class));
361
362         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForFloatingIPArpDelete", ID);
363         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage1", anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
364     }
365
366     @Test
367     public void testFindNeutronPortForFloatingIp() throws Exception {
368         NeutronPort neutronPort = mock(NeutronPort.class);
369         when(neutronPort.getDeviceOwner()).thenReturn(OWNER_FLOATING_IP);
370         when(neutronPort.getDeviceID()).thenReturn(ID);
371         List<NeutronPort> list_neutronPort = new ArrayList<>();
372         list_neutronPort.add(neutronPort);
373         INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
374         when(neutronPortCache.getAllPorts()).thenReturn(list_neutronPort);
375
376         MemberModifier.field(NeutronL3Adapter.class, "neutronPortCache").set(neutronL3Adapter , neutronPortCache);
377
378         assertEquals("Error, did not return the correct NeutronPort", neutronPort, Whitebox.invokeMethod(neutronL3Adapter, "findNeutronPortForFloatingIp", ID));
379     }
380
381     @Test
382     public void testFindOFPortForExtPatch() throws Exception {
383         ConfigurationService configurationService = mock(ConfigurationService.class);
384         when(configurationService.getPatchPortName(any(Pair.class))).thenReturn(PORT_INT);
385         MemberModifier.field(NeutronL3Adapter.class, "configurationService").set(neutronL3Adapter , configurationService);
386         List<Node> nodes = new ArrayList<>();
387         nodes.add(mock(Node.class));
388         NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
389         when(nodeCacheManager.getBridgeNodes()).thenReturn(nodes);
390         MemberModifier.field(NeutronL3Adapter.class, "nodeCacheManager").set(neutronL3Adapter , nodeCacheManager);
391         Southbound southbound = mock(Southbound.class);
392         when(southbound.getDataPathId(any(Node.class))).thenReturn(Long.valueOf(ID));
393         OvsdbTerminationPointAugmentation terminationPointOfBridge = mock(OvsdbTerminationPointAugmentation.class);
394         when(terminationPointOfBridge.getOfport()).thenReturn(Long.valueOf(ID));
395         when(southbound.getTerminationPointOfBridge(any(Node.class), anyString())).thenReturn(terminationPointOfBridge);
396         MemberModifier.field(NeutronL3Adapter.class, "southbound").set(neutronL3Adapter , southbound);
397
398         assertEquals("Error, did not return the correct NeutronPort", Long.valueOf(ID), Whitebox.invokeMethod(neutronL3Adapter, "findOFPortForExtPatch", Long.valueOf(ID)));
399     }
400
401     @Test
402     public void testHandleNeutronNetworkEvent() throws Exception {
403         // Nothing to be done here
404         Whitebox.invokeMethod(neutronL3Adapter, "handleNeutronNetworkEvent", mock(NeutronNetwork.class), Action.ADD);
405     }
406
407     @Test
408     public void testHandleInterfaceEvent() throws Exception {
409         Map<String, Pair<Long, Uuid>> neutronPortToDpIdCache = new HashMap<>();
410         // init instance variables
411         TenantNetworkManager tenantNetworkManager = mock(TenantNetworkManager.class);
412         MemberModifier.field(NeutronL3Adapter.class, "tenantNetworkManager").set(neutronL3Adapter , tenantNetworkManager);
413         MemberModifier.field(NeutronL3Adapter.class, "neutronPortToDpIdCache").set(neutronL3Adapter , neutronPortToDpIdCache);
414
415         // Mock variables
416         NodeId nodeId = mock(NodeId.class);
417         when(nodeId.getValue()).thenReturn(ID);
418         Node node = mock(Node.class);
419         when(node.getNodeId()).thenReturn(nodeId);
420
421         OvsdbTerminationPointAugmentation intf = mock(OvsdbTerminationPointAugmentation.class);
422         when(intf.getInterfaceUuid()).thenReturn(mock(Uuid.class));
423         when(intf.getName()).thenReturn(INTF_NAME);
424
425         NeutronPort neutronPort = mock(NeutronPort.class);
426         when(neutronPort.getPortUUID()).thenReturn(UUID);
427
428         when(tenantNetworkManager.getTenantPort(intf)).thenReturn(neutronPort);
429
430         // Suppress the called to these functions
431         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "getDpidForIntegrationBridge", Node.class));
432         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "handleInterfaceEventAdd", String.class, Long.class, Uuid.class));
433         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "handleInterfaceEventDelete", OvsdbTerminationPointAugmentation.class, Long.class));
434
435         PowerMockito.when(neutronL3Adapter, "getDpidForIntegrationBridge", any(Node.class)).thenReturn(45L);
436         Mockito.doNothing().when(neutronL3Adapter).handleNeutronPortEvent(any(NeutronPort.class), any(Action.class));
437
438         neutronL3Adapter.handleInterfaceEvent(node, intf, mock(NeutronNetwork.class), Action.ADD);
439         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("getDpidForIntegrationBridge", any(Node.class));
440         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("handleInterfaceEventAdd", any(String.class), anyLong(), any(Uuid.class));
441         Mockito.verify(neutronL3Adapter).handleNeutronPortEvent(neutronPort, Action.ADD);
442
443         neutronL3Adapter.handleInterfaceEvent(node, intf, mock(NeutronNetwork.class), Action.DELETE);
444         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("handleInterfaceEventDelete", any(OvsdbTerminationPointAugmentation.class), anyLong());
445         Mockito.verify(neutronL3Adapter).handleNeutronPortEvent(neutronPort, Action.DELETE);
446     }
447
448     @Test
449     public void testHandleInterfaceEventAdd() throws Exception {
450         Map<String, Pair<Long, Uuid>> neutronPortToDpIdCache = new HashMap<>();
451         // init instance variables
452         MemberModifier.field(NeutronL3Adapter.class, "neutronPortToDpIdCache").set(neutronL3Adapter , neutronPortToDpIdCache);
453         int temp = neutronPortToDpIdCache.size();
454
455         Whitebox.invokeMethod(neutronL3Adapter, "handleInterfaceEventAdd", "", Long.valueOf(5), mock(Uuid.class));
456
457         assertEquals("Error, did not add the port", temp+1, neutronPortToDpIdCache.size());
458     }
459
460     @SuppressWarnings("unchecked")
461     @Test
462     public void testHandleInterfaceEventDelete() throws Exception {
463         Map<String, Pair<Long, Uuid>> neutronPortToDpIdCache = new HashMap<>();
464         OvsdbTerminationPointAugmentation intf = mock(OvsdbTerminationPointAugmentation.class);
465         Uuid uuid = mock(Uuid.class);
466         when(intf.getInterfaceUuid()).thenReturn(uuid );
467         Pair<Long, Uuid> pair = mock(Pair.class);
468         when(pair.getRight()).thenReturn(uuid);
469
470         // init instance variables
471         neutronPortToDpIdCache.put("key", pair);
472         MemberModifier.field(NeutronL3Adapter.class, "neutronPortToDpIdCache").set(neutronL3Adapter , neutronPortToDpIdCache);
473         int temp = neutronPortToDpIdCache.size();
474
475         Whitebox.invokeMethod(neutronL3Adapter, "handleInterfaceEventDelete", intf, Long.valueOf(ID));
476
477         assertEquals("Error, did not remove the port", temp-1, neutronPortToDpIdCache.size());
478     }
479
480     @Test
481     public void testUpdateL3ForNeutronPort() throws Exception {
482         Map<String, String> networkIdToRouterMacCache = new HashMap<>();
483
484         Neutron_IPs neutronIp = mock(Neutron_IPs.class);
485         when(neutronIp.getIpAddress()).thenReturn(FIXED_IP_ADDRESS);
486         List<Neutron_IPs> neutronIps = new ArrayList<>();
487         neutronIps.add(neutronIp);
488         NeutronPort neutronPort = mock(NeutronPort.class);
489         when(neutronPort.getNetworkUUID()).thenReturn(UUID);
490         when(neutronPort.getMacAddress()).thenReturn(MAC_ADDRESS_2);
491         when(neutronPort.getFixedIPs()).thenReturn(neutronIps);
492         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
493         when(neutronNetwork.getProviderSegmentationID()).thenReturn(ID);
494         List<Node> nodes = new ArrayList<>();
495         nodes.add(mock(Node.class));
496         TenantNetworkManager tenantNetworkManager = mock(TenantNetworkManager.class);
497         MemberModifier.field(NeutronL3Adapter.class, "tenantNetworkManager").set(neutronL3Adapter , tenantNetworkManager);
498         when(tenantNetworkManager.isTenantNetworkPresentInNode(any(Node.class), eq(ID))).thenReturn(true);
499         PowerMockito.doReturn(15L).when(neutronL3Adapter, "getDpidForIntegrationBridge", any(Node.class));
500
501         // init instance variables
502         networkIdToRouterMacCache .put(UUID, MAC_ADDRESS);
503         MemberModifier.field(NeutronL3Adapter.class, "networkIdToRouterMacCache").set(neutronL3Adapter , networkIdToRouterMacCache);
504         INeutronNetworkCRUD neutronNetworkCache = mock(INeutronNetworkCRUD.class);
505         when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
506         MemberModifier.field(NeutronL3Adapter.class, "neutronNetworkCache").set(neutronL3Adapter , neutronNetworkCache);
507         NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
508         when(nodeCacheManager.getBridgeNodes()).thenReturn(nodes);
509         MemberModifier.field(NeutronL3Adapter.class, "nodeCacheManager").set(neutronL3Adapter , nodeCacheManager);
510         MemberModifier.field(NeutronL3Adapter.class, "flgDistributedARPEnabled").set(neutronL3Adapter , true);
511
512         // Suppress the called to these functions
513         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "getDpidForIntegrationBridge", Node.class));
514         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programL3ForwardingStage1", Node.class, Long.class, String.class, String.class, String.class, Action.class));
515         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programStaticArpStage1", Long.class, String.class, String.class, String.class, Action.class));
516
517         Whitebox.invokeMethod(neutronL3Adapter, "updateL3ForNeutronPort", neutronPort, false);
518         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("getDpidForIntegrationBridge", any(Node.class));
519         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programL3ForwardingStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
520         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage1", anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
521
522         Whitebox.invokeMethod(neutronL3Adapter, "updateL3ForNeutronPort", neutronPort, true);
523         PowerMockito.verifyPrivate(neutronL3Adapter, times(2)).invoke("getDpidForIntegrationBridge", any(Node.class));
524         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programL3ForwardingStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
525         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage1", anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
526     }
527
528     @Test
529     public void testProgramL3ForwardingStage1() throws Exception {
530
531         NodeId nodeId = mock(NodeId.class);
532         when(nodeId.getValue()).thenReturn(ID);
533         Node node = mock(Node.class);
534         when(node.getNodeId()).thenReturn(nodeId);
535
536         // Suppress the called to these functions
537         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programL3ForwardingStage2", Node.class, Long.class, String.class, String.class, String.class, Action.class));
538
539         // init instance variables
540         PowerMockito.when(neutronL3Adapter, "programL3ForwardingStage2", any(Node.class), anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD)).thenReturn(new Status(StatusCode.SUCCESS));
541         PowerMockito.when(neutronL3Adapter, "programL3ForwardingStage2", any(Node.class), anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE)).thenReturn(new Status(StatusCode.SUCCESS));
542
543
544         Whitebox.invokeMethod(neutronL3Adapter, "programL3ForwardingStage1", node, Long.valueOf(45), SEG_ID, MAC_ADDRESS, IP, Action.ADD);
545         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programL3ForwardingStage2", any(Node.class), anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
546
547
548         Whitebox.invokeMethod(neutronL3Adapter, "programL3ForwardingStage1", node, Long.valueOf(45), SEG_ID, MAC_ADDRESS, IP, Action.DELETE);
549         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programL3ForwardingStage2", any(Node.class), anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
550     }
551
552     @Test
553     public void testProgramL3ForwardingStage2() throws Exception {
554         NodeId nodeId = mock(NodeId.class);
555         when(nodeId.getValue()).thenReturn(ID);
556         Node node = mock(Node.class);
557         when(node.getNodeId()).thenReturn(nodeId);
558
559         assertEquals("Error, this not return the correct status code", new Status(StatusCode.BADREQUEST), Whitebox.invokeMethod(neutronL3Adapter, "programL3ForwardingStage2", node, Long.valueOf(45), SEG_ID, MAC_ADDRESS, MALFORM_IP, Action.ADD));
560
561         PowerMockito.mockStatic(InetAddress.class);
562         InetAddress inetAddress = mock(InetAddress.class);
563         PowerMockito.when(InetAddress.getByName(anyString())).thenReturn(inetAddress);
564
565         assertEquals("Error, this not return the correct status code", new Status(StatusCode.SUCCESS), Whitebox.invokeMethod(neutronL3Adapter, "programL3ForwardingStage2", node, Long.valueOf(45), SEG_ID, MAC_ADDRESS, IP, Action.ADD));
566     }
567
568     @Test
569     public void testProgramFlowsForNeutronRouterInterface() throws Exception {
570         Map<String, String> networkIdToRouterMacCache = new HashMap<>();
571         Map<String, List<Neutron_IPs>> networkIdToRouterIpListCache = new HashMap<>();
572         Map<String, NeutronRouter_Interface> subnetIdToRouterInterfaceCache = new HashMap<>();
573
574         NeutronRouter_Interface intf = mock(NeutronRouter_Interface.class);
575         when(intf.getPortUUID()).thenReturn(UUID);
576         when(intf.getSubnetUUID()).thenReturn(UUID);
577         Neutron_IPs neutronIp = mock(Neutron_IPs.class);
578         when(neutronIp.getIpAddress()).thenReturn(FIXED_IP_ADDRESS);
579         List<Neutron_IPs> ips = new ArrayList<>();
580         ips.add(neutronIp);
581         NeutronPort neutronPort = mock(NeutronPort.class);
582         when(neutronPort.getMacAddress()).thenReturn(MAC_ADDRESS);
583         when(neutronPort.getFixedIPs()).thenReturn(ips);
584         when(neutronPort.getNetworkUUID()).thenReturn(UUID);
585         NeutronSubnet neutronSubnet = mock(NeutronSubnet.class);
586         when(neutronSubnet.getNetworkUUID()).thenReturn(UUID);
587         when(neutronSubnet.getGatewayIP()).thenReturn(IP);
588         when(neutronSubnet.getCidr()).thenReturn("cidr");
589         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
590         when(neutronNetwork.getProviderSegmentationID()).thenReturn(ID);
591         when(neutronNetwork.getRouterExternal()).thenReturn(false); //might change that to true
592         when(neutronNetwork.getNetworkUUID()).thenReturn(UUID);
593         NeutronRouter neutronRouter = mock(NeutronRouter.class);
594
595         Node node = mock(Node.class);
596         List<Node> nodes = new ArrayList<>();
597         nodes.add(node);
598
599         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "getDpidForIntegrationBridge", Node.class));
600         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowsForNeutronRouterInterfacePair", Node.class, Long.class, NeutronRouter_Interface.class, NeutronRouter_Interface.class, NeutronNetwork.class, String.class, String.class, String.class, int.class, Action.class, Boolean.class));
601         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programFlowForNetworkFromExternal", Node.class, Long.class, String.class, String.class, String.class, int.class, Action.class));
602         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programStaticArpStage1", Long.class, String.class, String.class, String.class, Action.class));
603         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programIpRewriteExclusionStage1", Node.class, Long.class, String.class, String.class, Action.class));
604
605         // init instance variables
606         INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
607         PowerMockito.when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
608         PowerMockito.when(neutronPortCache.getAllPorts()).thenReturn(new ArrayList<NeutronPort>());
609         INeutronSubnetCRUD neutronSubnetCache = mock(INeutronSubnetCRUD.class);
610         PowerMockito.when(neutronSubnetCache.getSubnet(anyString())).thenReturn(neutronSubnet);
611         INeutronNetworkCRUD neutronNetworkCache = mock(INeutronNetworkCRUD.class);
612         PowerMockito.when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
613         NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
614         PowerMockito.when(nodeCacheManager.getBridgeNodes()).thenReturn(nodes);
615         MemberModifier.field(NeutronL3Adapter.class, "networkIdToRouterMacCache").set(neutronL3Adapter , networkIdToRouterMacCache);
616         MemberModifier.field(NeutronL3Adapter.class, "networkIdToRouterIpListCache").set(neutronL3Adapter , networkIdToRouterIpListCache);
617         MemberModifier.field(NeutronL3Adapter.class, "subnetIdToRouterInterfaceCache").set(neutronL3Adapter , subnetIdToRouterInterfaceCache);
618         MemberModifier.field(NeutronL3Adapter.class, "neutronPortCache").set(neutronL3Adapter , neutronPortCache);
619         MemberModifier.field(NeutronL3Adapter.class, "neutronSubnetCache").set(neutronL3Adapter , neutronSubnetCache);
620         MemberModifier.field(NeutronL3Adapter.class, "neutronNetworkCache").set(neutronL3Adapter , neutronNetworkCache);
621         MemberModifier.field(NeutronL3Adapter.class, "nodeCacheManager").set(neutronL3Adapter , nodeCacheManager);
622         PowerMockito.when(neutronL3Adapter, "getDpidForIntegrationBridge", any(Node.class)).thenReturn(45L);
623
624         int networkIdToRouterMacCacheSize, networkIdToRouterIpListCacheSize, subnetIdToRouterInterfaceCacheSize;
625         networkIdToRouterMacCacheSize = networkIdToRouterMacCache.size();
626         networkIdToRouterIpListCacheSize = networkIdToRouterIpListCache.size();
627         subnetIdToRouterInterfaceCacheSize = subnetIdToRouterInterfaceCache.size();
628
629         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForNeutronRouterInterface", intf, false);
630
631         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("getDpidForIntegrationBridge", any(Node.class));
632         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForNeutronRouterInterfacePair", any(Node.class), anyLong(), any(NeutronRouter_Interface.class), any(NeutronRouter_Interface.class), any(NeutronNetwork.class), anyString(), anyString(), anyString(), anyInt(), eq(Action.ADD), anyBoolean());
633         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowForNetworkFromExternal", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyInt(), eq(Action.ADD));
634         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage1", anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
635         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programIpRewriteExclusionStage1", any(Node.class), anyLong(), anyString(), anyString(), eq(Action.ADD));
636         assertEquals("Error, did not add the RouterMac", networkIdToRouterMacCacheSize, networkIdToRouterMacCache.size() -1);
637         assertEquals("Error, did not add the RouterIP", networkIdToRouterIpListCacheSize, networkIdToRouterIpListCache.size() -1);
638         assertEquals("Error, did not add the RouterInterface", subnetIdToRouterInterfaceCacheSize, subnetIdToRouterInterfaceCache.size() -1);
639
640         networkIdToRouterMacCache.put(UUID, MAC_ADDRESS);
641         networkIdToRouterIpListCache.put(UUID, ips);
642         subnetIdToRouterInterfaceCache.put(UUID, intf);
643         networkIdToRouterMacCacheSize = networkIdToRouterMacCache.size();
644         networkIdToRouterIpListCacheSize = networkIdToRouterIpListCache.size();
645         subnetIdToRouterInterfaceCacheSize = subnetIdToRouterInterfaceCache.size();
646
647         Whitebox.invokeMethod(neutronL3Adapter, "handleNeutronRouterInterfaceEvent", neutronRouter, intf, Action.DELETE);
648
649         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowsForNeutronRouterInterface", intf, true);
650         PowerMockito.verifyPrivate(neutronL3Adapter, times(2)).invoke("getDpidForIntegrationBridge", any(Node.class));
651         PowerMockito.verifyPrivate(neutronL3Adapter, times(2)).invoke("programFlowsForNeutronRouterInterfacePair", any(Node.class), anyLong(), any(NeutronRouter_Interface.class), any(NeutronRouter_Interface.class), any(NeutronNetwork.class), anyString(), anyString(), anyString(), anyInt(), eq(Action.DELETE), anyBoolean());
652         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programFlowForNetworkFromExternal", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyInt(), eq(Action.DELETE));
653         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage1", anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
654         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programIpRewriteExclusionStage1", any(Node.class), anyLong(), anyString(), anyString(), eq(Action.DELETE));
655         assertEquals("Error, did not remove the RouterMac", networkIdToRouterMacCacheSize, networkIdToRouterMacCache.size() +1);
656         assertEquals("Error, did not remove the RouterIP", networkIdToRouterIpListCacheSize, networkIdToRouterIpListCache.size() +1);
657         assertEquals("Error, did not remove the RouterInterface", subnetIdToRouterInterfaceCacheSize, subnetIdToRouterInterfaceCache.size() +1);
658     }
659
660     @Test
661     public void testProgramFlowForNetworkFromExternal() throws Exception {
662         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programRouterInterfaceStage1", Node.class, Long.class, String.class, String.class, String.class, String.class, int.class, Action.class));
663
664         Whitebox.invokeMethod(neutronL3Adapter, "programFlowForNetworkFromExternal", mock(Node.class), Long.valueOf(12), "", "", "", 4, Action.ADD);
665
666         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programRouterInterfaceStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt(), any(Action.class));
667     }
668
669     @Test
670     public void testProgramFlowsForNeutronRouterInterfacePair() throws Exception {
671         NeutronRouter_Interface srcNeutronRouterInterface = mock(NeutronRouter_Interface.class);
672         when(srcNeutronRouterInterface.getSubnetUUID()).thenReturn(UUID);
673         when(srcNeutronRouterInterface.getID()).thenReturn(ID);
674         when(srcNeutronRouterInterface.getPortUUID()).thenReturn(UUID);
675         NeutronRouter_Interface dstNeutronRouterInterface = mock(NeutronRouter_Interface.class);
676         NeutronNetwork neutronNetwork = mock(NeutronNetwork.class);
677         when(neutronNetwork.getTenantID()).thenReturn(ID);
678         when(neutronNetwork.getProviderSegmentationID()).thenReturn(ID);
679         Neutron_IPs ip = mock(Neutron_IPs.class);
680         when(ip.getIpAddress()).thenReturn(IP);
681         List<Neutron_IPs> ips = new ArrayList<>();
682         ips.add(ip);
683         ips.add(ip);
684         ips.add(ip);
685         NeutronPort neutronPort = mock(NeutronPort.class);
686         when(neutronPort.getMacAddress()).thenReturn(MAC_ADDRESS);
687         when(neutronPort.getFixedIPs()).thenReturn(ips);
688         NeutronSubnet neutronSubnet = mock(NeutronSubnet.class);
689         when(neutronSubnet.getNetworkUUID()).thenReturn(UUID);
690         when(neutronSubnet.getCidr()).thenReturn(CIDR);
691
692         INeutronSubnetCRUD neutronSubnetCache = mock(INeutronSubnetCRUD.class);
693         PowerMockito.when(neutronSubnetCache.getSubnet(anyString())).thenReturn(neutronSubnet);
694         MemberModifier.field(NeutronL3Adapter.class, "neutronSubnetCache").set(neutronL3Adapter , neutronSubnetCache);
695         INeutronNetworkCRUD neutronNetworkCache = mock(INeutronNetworkCRUD.class);
696         PowerMockito.when(neutronNetworkCache.getNetwork(anyString())).thenReturn(neutronNetwork);
697         MemberModifier.field(NeutronL3Adapter.class, "neutronNetworkCache").set(neutronL3Adapter , neutronNetworkCache);
698         INeutronPortCRUD neutronPortCache = mock(INeutronPortCRUD.class);
699         PowerMockito.when(neutronPortCache.getPort(anyString())).thenReturn(neutronPort);
700         MemberModifier.field(NeutronL3Adapter.class, "neutronPortCache").set(neutronL3Adapter , neutronPortCache);
701
702         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programRouterInterfaceStage1", Node.class, Long.class, String.class, String.class, String.class, String.class, int.class, Action.class));
703         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "getMaskLenFromCidr", String.class));
704
705         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForNeutronRouterInterfacePair", mock(Node.class), Long.valueOf(12), srcNeutronRouterInterface, dstNeutronRouterInterface, neutronNetwork, SEG_ID, MAC_ADDRESS, IP, 4, Action.ADD, false);
706         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programRouterInterfaceStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt(), any(Action.class));
707
708         Whitebox.invokeMethod(neutronL3Adapter, "programFlowsForNeutronRouterInterfacePair", mock(Node.class), Long.valueOf(12), srcNeutronRouterInterface, dstNeutronRouterInterface, neutronNetwork, SEG_ID, MAC_ADDRESS, IP, 4, Action.ADD, true);
709         PowerMockito.verifyPrivate(neutronL3Adapter, times(2)).invoke("programRouterInterfaceStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt(), any(Action.class));
710         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("getMaskLenFromCidr", anyString());
711         PowerMockito.verifyPrivate(neutronL3Adapter, times(4)).invoke("programFlowsForNeutronRouterInterfacePair", any(Node.class), anyLong(), any(NeutronRouter_Interface.class), any(NeutronRouter_Interface.class), any(NeutronNetwork.class), anyString(), anyString(), anyString(), anyInt(), any(Action.class), eq(false)); //3 + 1 above
712     }
713
714     @Test
715     public void testProgramRouterInterfaceStage1() throws Exception {
716
717         NodeId nodeId = mock(NodeId.class);
718         when(nodeId.getValue()).thenReturn(ID);
719         Node node = mock(Node.class);
720         when(node.getNodeId()).thenReturn(nodeId);
721
722         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programRouterInterfaceStage2", Node.class, Long.class, String.class, String.class, String.class, String.class, int.class, Action.class));
723
724         PowerMockito.when(neutronL3Adapter, "programRouterInterfaceStage2", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt(), any(Action.class)).thenReturn(new Status(StatusCode.SUCCESS));
725
726
727         Whitebox.invokeMethod(neutronL3Adapter, "programRouterInterfaceStage1", node, Long.valueOf(12), SEG_ID, SEG_ID, MAC_ADDRESS, IP, 4, Action.ADD);
728
729         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programRouterInterfaceStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt(), eq(Action.ADD));
730
731         Whitebox.invokeMethod(neutronL3Adapter, "programRouterInterfaceStage1", node, Long.valueOf(12), SEG_ID, SEG_ID, MAC_ADDRESS, IP, 4, Action.DELETE);
732
733         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programRouterInterfaceStage1", any(Node.class), anyLong(), anyString(), anyString(), anyString(), anyString(), anyInt(), eq(Action.DELETE));
734     }
735
736     @Test
737     public void testProgramRouterInterfaceStage2() throws Exception {
738         NodeId nodeId = mock(NodeId.class);
739         when(nodeId.getValue()).thenReturn(ID);
740         Node node = mock(Node.class);
741         when(node.getNodeId()).thenReturn(nodeId);
742
743         assertEquals("Error, this not return the correct status code", new Status(StatusCode.BADREQUEST), Whitebox.invokeMethod(neutronL3Adapter, "programRouterInterfaceStage2", node, Long.valueOf(45), SEG_ID, SEG_ID , MAC_ADDRESS, MALFORM_IP, 4, Action.ADD));
744
745         PowerMockito.mockStatic(InetAddress.class);
746         InetAddress inetAddress = mock(InetAddress.class);
747         PowerMockito.when(InetAddress.getByName(anyString())).thenReturn(inetAddress);
748
749         assertEquals("Error, this not return the correct status code", new Status(StatusCode.SUCCESS), Whitebox.invokeMethod(neutronL3Adapter, "programRouterInterfaceStage2", node, Long.valueOf(45), SEG_ID, SEG_ID, MAC_ADDRESS, IP, 4, Action.ADD));
750
751     }
752
753     @Test
754     public void testProgramStaticArpStage1() throws Exception {
755
756         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programStaticArpStage2", Long.class, String.class, String.class, String.class, Action.class));
757
758         PowerMockito.when(neutronL3Adapter, "programStaticArpStage2", anyLong(), anyString(), anyString(), anyString(), any(Action.class)).thenReturn(new Status(StatusCode.SUCCESS));
759
760
761         Whitebox.invokeMethod(neutronL3Adapter, "programStaticArpStage1", Long.valueOf(12), PORT_INT, MAC_ADDRESS, IP, Action.ADD);
762
763         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage2", anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
764
765         Whitebox.invokeMethod(neutronL3Adapter, "programStaticArpStage1", Long.valueOf(12), PORT_INT, MAC_ADDRESS, IP, Action.DELETE);
766
767         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programStaticArpStage2", anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
768     }
769
770     @Test
771     public void testProgramStaticArpStage2() throws Exception {
772         assertEquals("Error, this not return the correct status code", new Status(StatusCode.BADREQUEST), Whitebox.invokeMethod(neutronL3Adapter, "programStaticArpStage2", Long.valueOf(45), PORT_INT, MAC_ADDRESS, MALFORM_IP, Action.ADD));
773
774         PowerMockito.mockStatic(InetAddress.class);
775         InetAddress inetAddress = mock(InetAddress.class);
776         PowerMockito.when(InetAddress.getByName(anyString())).thenReturn(inetAddress);
777
778         assertEquals("Error, this not return the correct status code", new Status(StatusCode.SUCCESS), Whitebox.invokeMethod(neutronL3Adapter, "programStaticArpStage2", Long.valueOf(45), PORT_INT, MAC_ADDRESS, IP, Action.ADD));
779     }
780
781     @Test
782     public void testProgramInboundIpRewriteStage1() throws Exception {
783
784         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programInboundIpRewriteStage2", Long.class, Long.class, String.class, String.class, String.class, Action.class));
785
786         PowerMockito.when(neutronL3Adapter, "programInboundIpRewriteStage2", anyLong(), anyLong(), anyString(), anyString(), anyString(), any(Action.class)).thenReturn(new Status(StatusCode.SUCCESS));
787
788
789         Whitebox.invokeMethod(neutronL3Adapter, "programInboundIpRewriteStage1", Long.valueOf(12), Long.valueOf(12), PORT_INT, MAC_ADDRESS, IP, Action.ADD);
790
791         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programInboundIpRewriteStage2", anyLong(), anyLong(), anyString(), anyString(), anyString(), eq(Action.ADD));
792
793         Whitebox.invokeMethod(neutronL3Adapter, "programInboundIpRewriteStage1", Long.valueOf(12), Long.valueOf(12),PORT_INT, MAC_ADDRESS, IP, Action.DELETE);
794
795         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programInboundIpRewriteStage2", anyLong(), anyLong(), anyString(), anyString(), anyString(), eq(Action.DELETE));
796     }
797
798     @Test
799     public void testProgramInboundIpRewriteStage2() throws Exception {
800         assertEquals("Error, this not return the correct status code", new Status(StatusCode.BADREQUEST), Whitebox.invokeMethod(neutronL3Adapter, "programInboundIpRewriteStage2", Long.valueOf(45), Long.valueOf(45), SEG_ID, MAC_ADDRESS, IP, Action.ADD));
801
802         PowerMockito.mockStatic(InetAddress.class);
803         InetAddress inetAddress = mock(InetAddress.class);
804         PowerMockito.when(InetAddress.getByName(anyString())).thenReturn(inetAddress);
805
806         assertEquals("Error, this not return the correct status code", new Status(StatusCode.SUCCESS), Whitebox.invokeMethod(neutronL3Adapter, "programInboundIpRewriteStage2", Long.valueOf(45), Long.valueOf(45), SEG_ID, MAC_ADDRESS, IP, Action.ADD));
807     }
808
809     @Test
810     public void testProgramIpRewriteExclusionStage1() throws Exception {
811
812         NodeId nodeId = mock(NodeId.class);
813         when(nodeId.getValue()).thenReturn(ID);
814         Node node = mock(Node.class);
815         when(node.getNodeId()).thenReturn(nodeId);
816
817         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programIpRewriteExclusionStage2", Node.class, Long.class, String.class, String.class, Action.class));
818
819         PowerMockito.when(neutronL3Adapter, "programIpRewriteExclusionStage2", any(Node.class), anyLong(), anyString(), anyString(), any(Action.class)).thenReturn(new Status(StatusCode.SUCCESS));
820
821
822         Whitebox.invokeMethod(neutronL3Adapter, "programIpRewriteExclusionStage1", node, Long.valueOf(12), SEG_ID, CIDR, Action.ADD);
823
824         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programIpRewriteExclusionStage2", any(Node.class), anyLong(), anyString(), anyString(), eq(Action.ADD));
825
826         Whitebox.invokeMethod(neutronL3Adapter, "programIpRewriteExclusionStage1", node, Long.valueOf(12), SEG_ID, CIDR, Action.DELETE);
827
828         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programIpRewriteExclusionStage2", any(Node.class), anyLong(), anyString(), anyString(), eq(Action.DELETE));
829     }
830
831     @Test
832     public void testProgramIpRewriteExclusionStage2() throws Exception {
833         NodeId nodeId = mock(NodeId.class);
834         when(nodeId.getValue()).thenReturn(ID);
835         Node node = mock(Node.class);
836         when(node.getNodeId()).thenReturn(nodeId);
837
838         assertEquals("Error, this not return the correct status code", new Status(StatusCode.SUCCESS), Whitebox.invokeMethod(neutronL3Adapter, "programIpRewriteExclusionStage2", node, Long.valueOf(45), SEG_ID, CIDR, Action.ADD));
839     }
840
841     @SuppressWarnings("unchecked")
842     @Test
843     public void testProgramOutboundIpRewriteStage1() throws Exception{
844
845         MemberModifier.suppress(MemberMatcher.method(NeutronL3Adapter.class, "programOutboundIpRewriteStage2", floatingIpClass, Action.class));
846
847         PowerMockito.when(neutronL3Adapter, "programOutboundIpRewriteStage2", any(floatingIpClass), any(Action.class)).thenReturn(new Status(StatusCode.SUCCESS));
848
849
850         Whitebox.invokeMethod(neutronL3Adapter, "programOutboundIpRewriteStage1", floatingIpObject, Action.ADD);
851
852         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programOutboundIpRewriteStage2", any(floatingIpClass), eq(Action.ADD));
853
854         Whitebox.invokeMethod(neutronL3Adapter, "programOutboundIpRewriteStage1", floatingIpObject, Action.DELETE);
855
856         PowerMockito.verifyPrivate(neutronL3Adapter, times(1)).invoke("programOutboundIpRewriteStage2", any(floatingIpClass), eq(Action.DELETE));
857     }
858
859     /*@Test
860     public void testPrepareProgramOutboundIpRewriteStage2() throws Exception {
861         assertEquals("Error, did not return the correct status code", new Status(StatusCode.BADREQUEST), Whitebox.invokeMethod(neutronL3Adapter, "programOutboundIpRewriteStage2", floatingIpObject, Action.ADD));
862
863         PowerMockito.mockStatic(InetAddress.class);
864         InetAddress inetAddress = mock(InetAddress.class);
865         PowerMockito.when(InetAddress.getByName(anyString())).thenReturn(inetAddress);
866
867         assertEquals("Error, did not return the correct status code", new Status(StatusCode.SUCCESS), Whitebox.invokeMethod(neutronL3Adapter, "programOutboundIpRewriteStage2", floatingIpObject, Action.ADD));
868     }*/
869
870     @Test
871     public void testGetMaskLenFromCidr() throws Exception {
872         assertEquals("Error, did not return the correct mask", 32, Whitebox.invokeMethod(neutronL3Adapter, "getMaskLenFromCidr", IP_MASK));
873     }
874
875     @Test
876     public void testGetDpidForIntegrationBridge() throws Exception {
877         Southbound southbound = mock(Southbound.class);
878         ConfigurationService configurationService = mock(ConfigurationService.class);
879
880         MemberModifier.field(NeutronL3Adapter.class, "southbound").set(neutronL3Adapter , southbound);
881         MemberModifier.field(NeutronL3Adapter.class, "configurationService").set(neutronL3Adapter , configurationService);
882
883         PowerMockito.when(southbound.getBridge(any(Node.class), anyString())).thenReturn(mock(OvsdbBridgeAugmentation.class));
884         PowerMockito.when(configurationService.getIntegrationBridgeName()).thenReturn("");
885         PowerMockito.when(southbound.getDataPathId(any(Node.class))).thenReturn(45L);
886
887         assertEquals("Error, did not return the correct Dpid", 45L, Whitebox.invokeMethod(neutronL3Adapter, "getDpidForIntegrationBridge", mock(Node.class)));
888     }
889
890     @Test
891     public void testencodeExcplicitOFPort() throws Exception {
892         assertEquals("Error, did not correctly encode the port", OFPort, NeutronL3Adapter.encodeExcplicitOFPort(45L));
893     }
894
895     @Test
896     public void testSetDependencies() throws Exception {
897         EventDispatcher eventDispatcher = mock(EventDispatcher.class);
898         TenantNetworkManager tenantNetworkManager = mock(TenantNetworkManager.class);
899         ConfigurationService configurationService = mock(ConfigurationService.class);
900         ArpProvider arpProvider = mock(ArpProvider.class);
901         InboundNatProvider inboundNatProvider = mock(InboundNatProvider.class);
902         OutboundNatProvider outboundNatProvider = mock(OutboundNatProvider.class);
903         RoutingProvider routingProvider = mock(RoutingProvider.class);
904         L3ForwardingProvider l3ForwardingProvider = mock(L3ForwardingProvider.class);
905         NodeCacheManager nodeCacheManager = mock(NodeCacheManager.class);
906         Southbound southbound = mock(Southbound.class);
907
908         PowerMockito.mockStatic(ServiceHelper.class);
909         PowerMockito.when(ServiceHelper.getGlobalInstance(EventDispatcher.class, neutronL3Adapter)).thenReturn(eventDispatcher);
910         PowerMockito.when(ServiceHelper.getGlobalInstance(TenantNetworkManager.class, neutronL3Adapter)).thenReturn(tenantNetworkManager);
911         PowerMockito.when(ServiceHelper.getGlobalInstance(ConfigurationService.class, neutronL3Adapter)).thenReturn(configurationService);
912         PowerMockito.when(ServiceHelper.getGlobalInstance(ArpProvider.class, neutronL3Adapter)).thenReturn(arpProvider);
913         PowerMockito.when(ServiceHelper.getGlobalInstance(InboundNatProvider.class, neutronL3Adapter)).thenReturn(inboundNatProvider);
914         PowerMockito.when(ServiceHelper.getGlobalInstance(OutboundNatProvider.class, neutronL3Adapter)).thenReturn(outboundNatProvider);
915         PowerMockito.when(ServiceHelper.getGlobalInstance(RoutingProvider.class, neutronL3Adapter)).thenReturn(routingProvider);
916         PowerMockito.when(ServiceHelper.getGlobalInstance(L3ForwardingProvider.class, neutronL3Adapter)).thenReturn(l3ForwardingProvider);
917         PowerMockito.when(ServiceHelper.getGlobalInstance(NodeCacheManager.class, neutronL3Adapter)).thenReturn(nodeCacheManager);
918         PowerMockito.when(ServiceHelper.getGlobalInstance(Southbound.class, neutronL3Adapter)).thenReturn(southbound);
919
920         neutronL3Adapter.setDependencies(mock(ServiceReference.class));
921
922         assertEquals("Error, did not return the correct object", getAbstractHandlerField("eventDispatcher"),
923                 eventDispatcher);
924         assertEquals("Error, did not return the correct object", getField("tenantNetworkManager"), tenantNetworkManager);
925         assertEquals("Error, did not return the correct object", getField("configurationService"), configurationService);
926         assertEquals("Error, did not return the correct object", getField("arpProvider"), arpProvider);
927         assertEquals("Error, did not return the correct object", getField("inboundNatProvider"), inboundNatProvider);
928         assertEquals("Error, did not return the correct object", getField("outboundNatProvider"), outboundNatProvider);
929         assertEquals("Error, did not return the correct object", getField("routingProvider"), routingProvider);
930         assertEquals("Error, did not return the correct object", getField("l3ForwardingProvider"), l3ForwardingProvider);
931         assertEquals("Error, did not return the correct object", getField("nodeCacheManager"), nodeCacheManager);
932         assertEquals("Error, did not return the correct object", getField("southbound"), southbound);
933     }
934
935     @Test
936     public void testSetDependenciesObject() throws Exception{
937         MemberModifier.field(NeutronL3Adapter.class, "enabled").set(neutronL3Adapter , false);
938
939         INeutronNetworkCRUD iNeutronNetworkCRUD = mock(INeutronNetworkCRUD.class);
940         neutronL3Adapter.setDependencies(iNeutronNetworkCRUD);
941         assertEquals("Error, did not return the correct object", getField("neutronNetworkCache"), iNeutronNetworkCRUD);
942
943         INeutronPortCRUD iNeutronPortCRUD = mock(INeutronPortCRUD.class);
944         neutronL3Adapter.setDependencies(iNeutronPortCRUD);
945         assertEquals("Error, did not return the correct object", getField("neutronPortCache"), iNeutronPortCRUD);
946
947         INeutronSubnetCRUD iNeutronSubnetCRUD = mock(INeutronSubnetCRUD.class);
948         neutronL3Adapter.setDependencies(iNeutronSubnetCRUD);
949         assertEquals("Error, did not return the correct object", getField("neutronSubnetCache"), iNeutronSubnetCRUD);
950
951         ArpProvider arpProvider = mock(ArpProvider.class);
952         neutronL3Adapter.setDependencies(arpProvider);
953         assertEquals("Error, did not return the correct object", getField("arpProvider"), arpProvider);
954
955         InboundNatProvider inboundNatProvider = mock(InboundNatProvider.class);
956         neutronL3Adapter.setDependencies(inboundNatProvider);
957         assertEquals("Error, did not return the correct object", getField("inboundNatProvider"), inboundNatProvider);
958
959         OutboundNatProvider outboundNatProvider = mock(OutboundNatProvider.class);
960         neutronL3Adapter.setDependencies(outboundNatProvider);
961         assertEquals("Error, did not return the correct object", getField("outboundNatProvider"), outboundNatProvider);
962
963         RoutingProvider routingProvider = mock(RoutingProvider.class);
964         neutronL3Adapter.setDependencies(routingProvider);
965         assertEquals("Error, did not return the correct object", getField("routingProvider"), routingProvider);
966
967         L3ForwardingProvider l3ForwardingProvider = mock(L3ForwardingProvider.class);
968         neutronL3Adapter.setDependencies(l3ForwardingProvider);
969         assertEquals("Error, did not return the correct object", getField("l3ForwardingProvider"), l3ForwardingProvider);
970
971         MemberModifier.field(NeutronL3Adapter.class, "enabled").set(neutronL3Adapter , true);
972     }
973
974     private Object getAbstractHandlerField(String fieldName) throws Exception {
975         Field field = AbstractHandler.class.getDeclaredField(fieldName);
976         field.setAccessible(true);
977         return field.get(neutronL3Adapter);
978     }
979
980     private Object getField(String fieldName) throws Exception {
981         Field field = NeutronL3Adapter.class.getDeclaredField(fieldName);
982         field.setAccessible(true);
983         return field.get(neutronL3Adapter);
984     }
985
986     @SuppressWarnings("rawtypes")
987     private Object createFloatingIpObject() throws Exception{
988         Class clazz = Whitebox.getInnerClassType(NeutronL3Adapter.class, "FloatIpData");
989         Constructor [] constructors = clazz.getConstructors();
990         Constructor c  = constructors[0];
991         return c.newInstance(neutronL3Adapter, 415L, 415L, "a", "b", "c", "d", "e");
992     }
993 }