Merge "OF-overlay PolicyEnforcer tests, refactoring"
authorMartin Sunal <msunal@cisco.com>
Fri, 8 Jul 2016 07:20:11 +0000 (07:20 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 8 Jul 2016 07:20:11 +0000 (07:20 +0000)
12 files changed:
groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.controller.js
groupbasedpolicy-ui/module/src/main/resources/gbp/common/gbp.css
groupbasedpolicy-ui/module/src/main/resources/gbp/endpoints/side_panel_endpoints_detail.tpl.html
groupbasedpolicy-ui/module/src/main/resources/gbp/resolved-policy/resolved-policy.tpl.html
groupbasedpolicy-ui/module/src/main/resources/gbp/sfc/dialog-sfc-topology.tpl.html
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapper.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAware.java
neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java [new file with mode: 0644]
neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java [new file with mode: 0644]
neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/NeutronMapperDataBrokerTest.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/mapper/destination/DestinationMapperUtils.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/mapper/destination/DestinationMapperFlowsTest.java

index cef32943f1942d9cb757f6ea225f8d52c2352ee0..57c8f465b045427bb098e41d94ac17bdac8cbcb9 100644 (file)
@@ -7,13 +7,14 @@ define([
 
     angular.module('app.gbp').controller('RootGbpCtrl', RootGbpCtrl);
 
-    RootGbpCtrl.$inject = ['$filter', '$mdDialog', '$rootScope', '$scope', '$state',
+    RootGbpCtrl.$inject = ['$mdDialog', '$rootScope', '$scope', '$state',
         'EndpointsListService', 'NextTopologyService', 'ResolvedPolicyListService', 'RootGbpService',
         'TenantListService', 'SxpMappingListService'];
 
-    function RootGbpCtrl($filter, $mdDialog, $rootScope, $scope, $state,
+    function RootGbpCtrl($mdDialog, $rootScope, $scope, $state,
         EndpointsListService, NextTopologyService, ResolvedPolicyListService, RootGbpService,
         TenantListService, SxpMappingListService) {
+
         /* properties */
         $scope.apiType = 'operational';
         $scope.activeObject = null;
index b8ba13fdffb63c1d9f2a8753ac498a0557df3d54..60105a9216f2635d7dc3ac19589d6eeede6e6c05 100644 (file)
@@ -1,3 +1,7 @@
+#page_logo {
+    display: none;
+}
+
 .h100 {
     height:100%
 }
     color: rgba(0,0,0,0.26);
 }
 
-svg g.node text {
+.gbpUiWrapper svg, div#next-vpp-topo svg {
+    border: none;
+    background-image: none;
+}
+
+.gbpUiWrapper svg g.node text {
     pointer-events: auto !important;
 }
 
@@ -104,6 +113,8 @@ svg g.node text {
 #graph-container {
     padding-left: 0;
     background-color: #ffffff;
+    width: 100%;
+    height: 100%;
 }
 
 /* $mdDialog.confirm */
@@ -349,4 +360,4 @@ section.legendBox ul .line {
 
 .n-topology-nav-setting > span {
     color: #999999;
-}
\ No newline at end of file
+}
index 5f32b957a3dc0302c23e1df5211a4a61251765a5..cc9487d348babfc33b0aa16685b8daaf35213360 100644 (file)
         <span flex="35"><strong>Address</strong></span><span flex>{{ sidePanelObject.data.address }}</span>
     </div>
     <md-divider style="margin-bottom: 10px; margin-top: 10px;"></md-divider>
-    <md-subheader class="md-secondary" ng-if="sidePanelObject.data['network-containment']['network-domain-type'].length">Network domain</md-subheader>
-    <div layout="row" class="layout-padding-lr15 .layout-padding-b15 layout-row" ng-if="sidePanelObject.data['network-containment']['network-domain-id'].length">
-        <span flex="35"><strong>Id</strong></span><span flex>{{ sidePanelObject.data['network-containment']['network-domain-id'] }}</span>
-    </div>
-    <div layout="row" class="layout-padding-lr15 .layout-padding-b15 layout-row" ng-if="sidePanelObject.data['network-containment']['network-domain-type'].length">
-        <span flex="35"><strong>type</strong></span><span flex>{{ sidePanelObject.data['network-containment']['network-domain-type'] }}</span>
-    </div>
-    <!-- <md-subheader class="md-secondary"></md-subheader> -->
+    <section ng-if="sidePanelObject.data['network-containment']['network-domain-type'].length">
+        <md-subheader class="md-secondary" style="color: rgb(33,150,243);">Network domain</md-subheader>
+        <div layout="row" class="layout-padding-lr15 .layout-padding-b15 layout-row">
+            <span flex="35"><strong>Id</strong></span><span flex>{{ sidePanelObject.data['network-containment']['network-domain-id'] }}</span>
+        </div>
+        <div layout="row" class="layout-padding-lr15 .layout-padding-b15 layout-row">
+            <span flex="35"><strong>type</strong></span><span flex>{{ sidePanelObject.data['network-containment']['network-domain-type'] }}</span>
+        </div>
+        <md-divider style="margin-bottom: 10px; margin-top: 10px;"></md-divider>
+    </section>
     <div layout="row" class="layout-padding-lr15 .layout-padding-b15 layout-row" ng-if="sidePanelObject.data.condition.length">
         <span flex="35"><strong>Condition</strong></span><span ng-repeat="cndt in sidePanelObject.data.condition">{{cndt}}<span ng-if="!$last">, </span>
         </span>
index 42cbf7e630662fdfffd7278fdd820b8b3dd1c715..fbc135fb704df412658ba4924f9f8ec1e9f00c41 100644 (file)
@@ -1,4 +1,4 @@
-<div id="topology-container" flex>
+<div id="topology-container" flex style="height: 100%;">
     <section class="legendBox">
         <md-button md-no-ink class="md-primary reload-button" ng-click="reloadTopology()">
             <i class="material-icons">sync</i> Reload topology
index e2b6458cb1d323e5abff9e260e4a10368a3b73ba..f4e12c884aceb1811dcf3cfac814e2c864096d19 100644 (file)
@@ -2,7 +2,7 @@
     <md-toolbar>
         <div class="md-toolbar-tools">
             <h2 style="color: white">
-                Detail for chain {{chain.data.name}}
+                Detail for chain {{chain.data.name}} ({{chain.data.symmetric ? 'Symmetric' : 'Asymmetric'}})
             </h2>
             <span flex></span>
             <md-button class="md-icon-button" ng-click="closeDialog()" aria-label="close button">
index 207fc3357819479ea344b40f6616515be69e8ed1..71456e34497b4cd594c2ea2e7f83408de08eda9f 100644 (file)
@@ -68,6 +68,8 @@ import com.google.common.collect.PeekingIterator;
 
 public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoCloseable {
 
+    public static final String EXC_MSG_UNKNOWN_MODIFICATION_TYPE_WITHIN_DATA = "Unknown modification type within data ";
+
     private final static SecurityRuleBuilder EIG_INGRESS_IPV4_SEC_RULE_BUILDER = new SecurityRuleBuilder()
         .setUuid(new Uuid("0a629f80-2408-11e6-b67b-9e71128cae77"))
         .setDirection(DirectionIngress.class)
@@ -181,7 +183,7 @@ public class NeutronMapper implements DataTreeChangeListener<Neutron>, AutoClose
                     }
                     break;
                 default:
-                    throw new IllegalStateException("Unknown modification type within data " + dataModif);
+                    throw new IllegalStateException(EXC_MSG_UNKNOWN_MODIFICATION_TYPE_WITHIN_DATA + dataModif);
             }
         }
     }
index 8c42a7454f0d4ab0dfadea217bba9589d6cc8897..bd2a45faaa7abaddfe05cdd5481be721c38b2704 100644 (file)
@@ -67,7 +67,7 @@ public class NeutronNetworkAware implements NeutronAware<Network> {
         LOG.trace("created network - {}", network);
         ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction();
         TenantId tenantId = new TenantId(network.getTenantId().getValue());
-        Name name = null;
+        Name name;
         ContextId ctxId = new ContextId(network.getUuid().getValue());
         ForwardingContextBuilder fwdCtxBuilder = new ForwardingContextBuilder()
         .setContextId(ctxId)
@@ -77,7 +77,6 @@ public class NeutronNetworkAware implements NeutronAware<Network> {
                 name = new Name(network.getName());
                 fwdCtxBuilder.setName(name);
             } catch (Exception e) {
-                name = null;
                 LOG.info("Name of Neutron Network '{}' is ignored.", network.getName());
                 LOG.debug("Name exception", e);
             }
diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/NeutronMapperTest.java
new file mode 100644 (file)
index 0000000..b68e3e1
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.neutron.mapper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Set;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.groupbasedpolicy.neutron.mapper.mapping.NeutronNetworkAware;
+import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.ext.rev150712.NetworkL3Extension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.ext.rev150712.NetworkL3ExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.NeutronBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.SecurityGroups;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.SecurityGroupsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.security.groups.SecurityGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.secgroups.rev150712.security.groups.attributes.security.groups.SecurityGroupBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class NeutronMapperTest extends NeutronMapperDataBrokerTest {
+
+    private final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
+    private final Uuid networkUuid = new Uuid("dddddddd-dddd-dddd-dddd-dddddddddddd");
+    private final Uuid networkUuid2 = new Uuid("dddddddd-dddd-dddd-dddd-ddddddddddd2");
+
+    private DataBroker dataBroker;
+    private RpcProviderRegistry rpcProvider;
+    private EndpointService epService;
+    private BaseEndpointService baseEpService;
+
+    private DataObjectModification<Neutron> rootNode;
+    private Set<DataTreeModification<Neutron>> changes;
+    private Neutron oldNeutronBefore;
+    private Neutron oldNeutronAfter;
+
+    private NeutronMapper mapper;
+    private DataObjectModification<Network> networkModif;
+    private Network networkBefore;
+    private Network networkAfter;
+    private NetworkL3Extension networkL3Extension;
+
+    @Before
+    public void init() {
+        dataBroker = getDataBroker();
+        epService = mock(EndpointService.class);
+        baseEpService = mock(BaseEndpointService.class);
+        rpcProvider = mock(RpcProviderRegistry.class);
+        when(rpcProvider.getRpcService(EndpointService.class)).thenReturn(epService);
+        when(rpcProvider.getRpcService(BaseEndpointService.class)).thenReturn(baseEpService);
+
+        mapper = new NeutronMapper(dataBroker, rpcProvider);
+
+        networkL3Extension = new NetworkL3ExtensionBuilder().setExternal(true).build();
+
+        rootNode = mock(DataObjectModification.class);
+
+        networkModif = mock(DataObjectModification.class);
+        networkBefore = new NetworkBuilder().setTenantId(tenantUuid).setUuid(networkUuid).build();
+        networkAfter = new NetworkBuilder().setTenantId(tenantUuid)
+            .setUuid(networkUuid2)
+            .addAugmentation(NetworkL3Extension.class, networkL3Extension)
+            .build();
+        when(networkModif.getDataType()).thenReturn(NeutronNetworkAware.NETWORK_WILDCARD_IID.getTargetType());
+
+        when(networkModif.getDataBefore()).thenReturn(networkBefore);
+        when(networkModif.getDataAfter()).thenReturn(networkAfter);
+
+        when(rootNode.getModifiedChildren()).thenReturn(ImmutableSet.of(networkModif));
+
+        DataTreeModification<Neutron> change = mock(DataTreeModification.class);
+        when(change.getRootNode()).thenReturn(rootNode);
+
+        changes = ImmutableSet.of(change);
+
+        oldNeutronBefore = new NeutronBuilder().build();
+        SecurityGroup sg = new SecurityGroupBuilder().setTenantId(tenantUuid).setUuid(MappingUtils.EIG_UUID).build();
+        SecurityGroups securityGroups = new SecurityGroupsBuilder().setSecurityGroup(ImmutableList.of(sg)).build();
+        oldNeutronAfter = new NeutronBuilder().setSecurityGroups(securityGroups).build();
+    }
+
+    @Test
+    public void testConstructor() throws IOException {
+        DataBroker dataBrokerSpy = spy(dataBroker);
+        NeutronMapper other = new NeutronMapper(dataBrokerSpy, rpcProvider);
+
+        verify(dataBrokerSpy).registerDataTreeChangeListener(new DataTreeIdentifier<>(
+                LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(Neutron.class).build()), other);
+
+        other.close();
+    }
+
+    @Test
+    public void test_Write_withNetworkCreate() {
+        when(networkModif.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        when(networkModif.getDataBefore()).thenReturn(null);
+        when(rootNode.getDataBefore()).thenReturn(oldNeutronBefore);
+        when(rootNode.getDataAfter()).thenReturn(oldNeutronAfter);
+
+        mapper.onDataTreeChanged(changes);
+        assertNetworkExists(networkAfter);
+    }
+
+    @Test
+    public void test_Write_withNetworkUpdate() {
+        when(networkModif.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        when(networkModif.getDataBefore()).thenReturn(null);
+        when(networkModif.getDataAfter()).thenReturn(networkBefore);
+        when(rootNode.getDataBefore()).thenReturn(oldNeutronBefore);
+        when(rootNode.getDataAfter()).thenReturn(oldNeutronAfter);
+
+        mapper.onDataTreeChanged(changes);
+
+        assertNetworkExists(networkBefore);
+        assertNetworkNotExists(networkAfter);
+
+        when(networkModif.getDataBefore()).thenReturn(networkBefore);
+        when(networkModif.getDataAfter()).thenReturn(networkAfter);
+
+        mapper.onDataTreeChanged(changes);
+        // no-op in NeutronNetworkAware#onUpdated
+    }
+
+    @Test
+    public void test_Delete() {
+        when(networkModif.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+        when(rootNode.getDataBefore()).thenReturn(oldNeutronBefore);
+        when(rootNode.getDataAfter()).thenReturn(oldNeutronAfter);
+
+        mapper.onDataTreeChanged(changes);
+    }
+
+    @Test
+    public void test_SubtreeModified() {
+        when(networkModif.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        when(rootNode.getDataBefore()).thenReturn(oldNeutronBefore);
+        when(rootNode.getDataAfter()).thenReturn(oldNeutronAfter);
+
+        mapper.onDataTreeChanged(changes);
+    }
+
+    private void assertNetworkExists(Network network) {
+        Optional<L3Context> opt = getL3ContextOptional(network);
+        if (opt.isPresent()) {
+            assertEquals(network.getUuid().getValue(), opt.get().getId().getValue());
+        } else {
+            fail("no network in DS, Uuid:" + network.getUuid());
+        }
+    }
+
+    private void assertNetworkNotExists(Network network) {
+        Optional<L3Context> opt = getL3ContextOptional(network);
+        if (opt.isPresent()) {
+            assertNotEquals(network.getUuid().getValue(), opt.get().getId().getValue());
+        }
+    }
+
+    private Optional<L3Context> getL3ContextOptional(Network network) {
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        TenantId tenantId = new TenantId(network.getTenantId().getValue());
+        ContextId l3CtxId = new ContextId(network.getUuid().getValue());
+        L3ContextId l3ContextId = new L3ContextId(l3CtxId);
+        InstanceIdentifier<L3Context> l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId);
+        return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rTx);
+    }
+}
diff --git a/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java b/neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronNetworkAwareDataStoreTest.java
new file mode 100644 (file)
index 0000000..a56822f
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.groupbasedpolicy.neutron.mapper.mapping;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import com.google.common.base.Optional;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.neutron.mapper.test.NeutronMapperDataBrokerTest;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.util.IidFactory;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L3Context;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.NetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.provider.ext.rev150712.NetworkProviderExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+public class NeutronNetworkAwareDataStoreTest extends NeutronMapperDataBrokerTest {
+
+    private final Uuid tenantUuid = new Uuid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
+    private final Uuid networkUuid = new Uuid("dddddddd-dddd-dddd-dddd-dddddddddddd");
+
+    private DataBroker dataBroker;
+    private NeutronNetworkAware networkAware;
+    private Neutron neutron;
+    private Future<RpcResult<Void>> futureRpcResult;
+    private Future<RpcResult<Void>> futureRpcFail;
+    private RpcResult<Void> rpcResult;
+    private RpcResult<Void> rpcFail;
+    private Network network;
+    private NetworkProviderExtension providerExtension;
+
+    @Before
+    public void init() throws ExecutionException, InterruptedException {
+        futureRpcResult = mock(Future.class);
+        futureRpcFail = mock(Future.class);
+        rpcResult = mock(RpcResult.class);
+        rpcFail = mock(RpcResult.class);
+        when(rpcResult.isSuccessful()).thenReturn(true);
+        when(rpcFail.isSuccessful()).thenReturn(false);
+        dataBroker = getDataBroker();
+        neutron = mock(Neutron.class);
+
+        when(futureRpcResult.get()).thenReturn(rpcResult);
+        when(futureRpcFail.get()).thenReturn(rpcFail);
+
+        providerExtension = new NetworkProviderExtensionBuilder().setPhysicalNetwork("physicalNetwork")
+            .setSegmentationId("segmentationId")
+            .build();
+
+        network = new NetworkBuilder().setTenantId(tenantUuid)
+            .setUuid(networkUuid)
+            .setName("networkName")
+            .addAugmentation(NetworkProviderExtension.class, providerExtension)
+            .build();
+
+        networkAware = new NeutronNetworkAware(dataBroker);
+    }
+
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
+    @Test
+    public void testConstructor_invalidArgument() throws NullPointerException {
+        thrown.expect(NullPointerException.class);
+        new NeutronNetworkAware(null);
+    }
+
+    @Test
+    public void testOnCreated() {
+
+        networkAware.onCreated(network, neutron);
+
+        assertNetworkExists(network);
+    }
+
+    @Test
+    public void testOnCreated_incorrectName() {
+        Network network = new NetworkBuilder().setTenantId(tenantUuid).setName("123").setUuid(networkUuid).build();
+
+        networkAware.onCreated(network, neutron);
+
+        assertNetworkExists(network);
+    }
+
+    @Test
+    public void testOnDeleted() {
+        Network network =
+                new NetworkBuilder().setTenantId(tenantUuid).setName("networkName").setUuid(networkUuid).build();
+
+        assertNetworkNotExists(network);
+
+        networkAware.onCreated(network, neutron);
+
+        assertNetworkExists(network);
+
+        networkAware.onDeleted(network, neutron, neutron);
+
+        assertNetworkNotExists(network);
+    }
+
+    @Test
+    public void testOnUpdated() {
+        Network network =
+                new NetworkBuilder().setTenantId(tenantUuid).setName("networkName").setUuid(networkUuid).build();
+
+        networkAware.onUpdated(network, network, neutron, neutron);
+        // no op
+    }
+
+    private void assertNetworkExists(Network network) {
+        Optional<L3Context> opt = getL3ContextOptional(network);
+        if (opt.isPresent()) {
+            assertEquals(network.getUuid().getValue(), opt.get().getId().getValue());
+        } else {
+            fail("no network in DS, Uuid:" + network.getUuid());
+        }
+    }
+
+    private void assertNetworkNotExists(Network network) {
+        Optional<L3Context> opt = getL3ContextOptional(network);
+        if (opt.isPresent()) {
+            assertNotEquals(network.getUuid().getValue(), opt.get().getId().getValue());
+        }
+    }
+
+    private Optional<L3Context> getL3ContextOptional(Network network) {
+        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        TenantId tenantId = new TenantId(network.getTenantId().getValue());
+        ContextId l3CtxId = new ContextId(network.getUuid().getValue());
+        L3ContextId l3ContextId = new L3ContextId(l3CtxId);
+        InstanceIdentifier<L3Context> l3ContextIid = IidFactory.l3ContextIid(tenantId, l3ContextId);
+        return DataStoreHelper.readFromDs(LogicalDatastoreType.CONFIGURATION, l3ContextIid, rTx);
+    }
+
+}
index c0ea1a20b189a98929324cb09518574b83b54cd6..19f4a126d82967edb64ac8a4c76ca3eda3ed8cb7 100644 (file)
@@ -8,6 +8,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.forwarding.rev160427.Forwarding;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.neutron.gbp.mapper.rev150513.Mappings;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.Tenants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
 
 /**
  * Loads only modules of GBP and it's dependencies for data broker.
@@ -18,7 +19,7 @@ public class NeutronMapperDataBrokerTest extends CustomDataBrokerTest {
 
     @Override
     public Collection<Class<?>> getClassesFromModules() {
-        return ImmutableList.<Class<?>>of(Tenants.class, Forwarding.class, SubnetAugmentForwarding.class,
+        return ImmutableList.<Class<?>>of(Neutron.class, Tenants.class, Forwarding.class, SubnetAugmentForwarding.class,
                 Mappings.class);
     }
 
index 48290785245513eb4efe33122d43157361fe21b8..aefa5ba6aa6a3ba170529f03b7f3cbce87bd6ee1 100644 (file)
@@ -62,7 +62,7 @@ class DestinationMapperUtils {
     }
 
     L3Context getL3ContextForSubnet(IndexedTenant indexedTenant, Subnet subnet) {
-        if (indexedTenant == null || subnet.getParent() == null) {
+        if (indexedTenant == null || subnet == null || subnet.getParent() == null) {
             return null;
         }
         return indexedTenant.resolveL3Context(new L2FloodDomainId(subnet.getParent().getValue()));
index 8605c94db5d9845f2efcf3578542648b3bea49a5..01de864bc0c0192c816da57414389d6b27dd92e1 100644 (file)
@@ -1,9 +1,45 @@
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.destination;
 
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyShort;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.ARP;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.IPv4;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.IPv6;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.RegMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.addNxRegMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.applyActionIns;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.bytesFromHexString;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.decNwTtlAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.ethernetMatch;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.gotoTableIns;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.groupAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadArpOpAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadArpShaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadArpSpaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadRegAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIPv4Action;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxLoadTunIdAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxMoveArpShaToArpThaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxMoveArpSpaToArpTpaAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.nxMoveEthSrcToEthDstAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.outputAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.setDlDstAction;
+import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.setDlSrcAction;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
 import org.opendaylight.groupbasedpolicy.dto.IndexedTenant;
 import org.opendaylight.groupbasedpolicy.dto.PolicyInfo;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
@@ -16,7 +52,6 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.OrdinalFactory;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.mapper.MapperUtilsTest;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
@@ -30,7 +65,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.M
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.SubnetId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
@@ -39,6 +73,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3PrefixBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContextBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.TenantBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.PolicyBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.Subnet;
@@ -58,25 +93,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev14
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg7;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import java.lang.reflect.Field;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static org.mockito.Mockito.*;
-import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
 
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ OrdinalFactory.class })
 public class DestinationMapperFlowsTest extends MapperUtilsTest {
 
     private DestinationMapperFlows flows;
+    private DestinationMapperUtils utils;
+    private Tenant tenant;
+    private IndexedTenant indexedTenant;
 
     @Before
     public void init() throws Exception {
@@ -85,9 +108,19 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         policyInfo = mock(PolicyInfo.class);
         ctx = mock(OfContext.class);
         ofWriter = mock(OfWriter.class);
+
         tableId = 3;
-        flows = new DestinationMapperFlows(new DestinationMapperUtils(ctx), NODE_ID, tableId);
-        resetPolicyOrdinalCounterValue();
+
+        tenant = buildTenant().build();
+        indexedTenant = new IndexedTenant(tenant);
+
+        when(ctx.getTenant(TENANT_ID)).thenReturn(indexedTenant);
+        when(ctx.getEndpointManager()).thenReturn(endpointManager);
+        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+
+        utils = new DestinationMapperUtils(ctx);
+        flows = new DestinationMapperFlows(utils, NODE_ID, tableId);
+        OrdinalFactory.resetPolicyOrdinalValue();
     }
 
     @Test
@@ -141,14 +174,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         externalConnectors.add(new NodeConnectorId(CONNECTOR_0));
         externalConnectors.add(new NodeConnectorId(CONNECTOR_1));
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createExternalL2Flow(tableId, 100, endpointBuilder.build(), externalConnectors, ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -158,12 +185,12 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         Set<NodeConnectorId> externalConnectors = new HashSet<>();
         externalConnectors.add(new NodeConnectorId(OPENFLOW + CONNECTOR_0.getValue()));
         externalConnectors.add(new NodeConnectorId(OPENFLOW + CONNECTOR_1.getValue()));
-        Endpoint endpoint = endpointBuilder.build();
-
+        Endpoint endpoint = endpointBuilder.setTenant(tenant.getId()).build();
 
-        MatchBuilder matchBuilder = new MatchBuilder()
-                .setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(), null));
-        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) 3));
+        MatchBuilder matchBuilder =
+                new MatchBuilder().setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(), null));
+        OrdinalFactory.EndpointFwdCtxOrdinals ord = utils.getEndpointOrdinals(endpoint);
+        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) ord.getBdId()));
         Match match = matchBuilder.build();
 
         List<Action> applyActions = new ArrayList<>();
@@ -173,11 +200,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
 
         ArrayList<Instruction> instructions = new ArrayList<>();
         instructions.add(applyActionsIns);
@@ -188,14 +213,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         FlowId flowId = FlowIdUtils.newFlowId(tableId, "externalL2", match);
         Flow flow = buildFlow(flowId, tableId, 100, match, instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createExternalL2Flow(tableId, 100, endpointBuilder.build(), externalConnectors, ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -211,16 +230,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         externalConnectors.add(new NodeConnectorId(CONNECTOR_0));
         externalConnectors.add(new NodeConnectorId(CONNECTOR_1));
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
                 ofWriter);
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verifyZeroInteractions(ofWriter);
     }
 
@@ -236,16 +248,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         externalConnectors.add(new NodeConnectorId(CONNECTOR_0));
         externalConnectors.add(new NodeConnectorId(CONNECTOR_1));
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
                 ofWriter);
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verifyZeroInteractions(ofWriter);
     }
 
@@ -271,18 +276,16 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         applyActions.addAll(l3ApplyActions);
 
         MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, MAC_1, IPv4))
-                .setLayer3Match(new Ipv4MatchBuilder()
-                .setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build());
+            .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32))
+                .build());
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
@@ -292,16 +295,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         FlowId flowid = FlowIdUtils.newFlowId(tableId, "externalL3", match);
         Flow flow = buildFlow(flowid, tableId, 90, match, instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
                 ofWriter);
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -327,18 +323,16 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         applyActions.addAll(l3ApplyActions);
 
         MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, MAC_1, IPv6))
-                .setLayer3Match(new Ipv6MatchBuilder()
-                .setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128)).build());
+            .setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128))
+                .build());
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 0));
         Match match = matchBuilder.build();
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
@@ -348,16 +342,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         FlowId flowid = FlowIdUtils.newFlowId(tableId, "externalL3", match);
         Flow flow = buildFlow(flowid, tableId, 90, match, instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createExternalL3RoutedFlow(tableId, 90, endpoint, gateway, l3AddressBuilder.build(), externalConnectors,
                 ofWriter);
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -366,15 +353,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_0, CONNECTOR_0);
         Endpoint endpoint = endpointBuilder.build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createLocalL2Flow(tableId, 80, endpoint, ofWriter);
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verifyZeroInteractions(ofWriter);
     }
 
@@ -383,7 +363,7 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         NodeConnectorId connectorId = new NodeConnectorId(OPENFLOW + CONNECTOR_0.getValue());
         EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_0, connectorId);
         endpointBuilder.setNetworkContainment(SUBNET_0);
-        Endpoint endpoint = endpointBuilder.build();
+        Endpoint endpoint = endpointBuilder.setTenant(tenant.getId()).build();
 
         List<Action> applyActions = new ArrayList<>();
         applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(1)));
@@ -392,11 +372,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
 
         ArrayList<Instruction> instructions = new ArrayList<>();
         instructions.add(applyActionsIns);
@@ -404,23 +382,17 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         instructionsBuilder.setInstruction(instructions);
 
-        MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(),
-                null));
-        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) 3));
+        MatchBuilder matchBuilder =
+                new MatchBuilder().setEthernetMatch(ethernetMatch(null, endpoint.getMacAddress(), null));
+        OrdinalFactory.EndpointFwdCtxOrdinals ord = utils.getEndpointOrdinals(endpoint);
+        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) ord.getBdId()));
         Match match = matchBuilder.build();
 
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "localL2", match), tableId, 80, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createLocalL2Flow(tableId, 80, endpoint, ofWriter);
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -457,12 +429,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         destSubnetBuilder.setId(SUBNET_1);
         Subnet destSubnet = destSubnetBuilder.build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
         flows.createLocalL3RoutedFlow(tableId, 80, endpoint, null, localSubnet, destSubnet, ofWriter);
-        verify(ctx, times(1)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -487,12 +455,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         destSubnetBuilder.setParent(L2FD_ID);
         Subnet destSubnet = destSubnetBuilder.build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
         flows.createLocalL3RoutedFlow(tableId, 80, endpoint, null, localSubnet, destSubnet, ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -518,14 +482,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         l3AddressBuilder.setIpAddress(null);
         L3Address l3Address = l3AddressBuilder.build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createLocalL3RoutedFlow(tableId, 80, endpoint, l3Address, localSubnet, destSubnet, ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -568,17 +526,16 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
 
         MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, destMac, IPv4))
-                .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build());
+            .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32))
+                .build());
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
@@ -587,14 +544,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "localL3", match), tableId, 80, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createLocalL3RoutedFlow(tableId, 80, endpoint, l3Address, localSubnet, destSubnet, ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -604,7 +555,7 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         MacAddress destMac = DestinationMapper.ROUTER_MAC;
         OfOverlayContextBuilder ofOverlayContextBuilder = new OfOverlayContextBuilder();
         ofOverlayContextBuilder.setNodeConnectorId(connectorId);
-        EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1,MAC_1, connectorId);
+        EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, connectorId);
         endpointBuilder.addAugmentation(OfOverlayContext.class, ofOverlayContextBuilder.build());
         endpointBuilder.setTenant(getTestIndexedTenant().getTenant().getId());
         endpointBuilder.setNetworkContainment(SUBNET_0);
@@ -637,17 +588,16 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
 
         MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, destMac, IPv6))
-                .setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128)).build());
+            .setLayer3Match(new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(IPV6_1.getValue() + IP_PREFIX_128))
+                .build());
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
@@ -656,14 +606,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "localL3", match), tableId, 80, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createLocalL3RoutedFlow(tableId, 80, endpoint, l3Address, localSubnet, destSubnet, ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -671,15 +615,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
     public void createRemoteL2Flow_exceptionCaught() {
         EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_0);
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createRemoteL2Flow(tableId, 70, endpointBuilder.build(), null, null, new NodeConnectorId(CONNECTOR_1),
                 ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -687,8 +625,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
     public void createRemoteL2Flow_ipV4() {
         NodeConnectorId connectorId = new NodeConnectorId(OPENFLOW + CONNECTOR_1.getValue());
         IpAddress ipAddress = new IpAddress(IPV4_0);
-        EndpointBuilder endpointBuilder = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_0);
-        EndpointBuilder peerEndpointBuilder = buildEndpoint(IPV4_1, MAC_0, CONNECTOR_1);
+        Endpoint endpoint = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_0).setTenant(tenant.getId()).build();
+        Endpoint peerEndpoint = buildEndpoint(IPV4_1, MAC_0, CONNECTOR_1).build();
 
         List<Action> applyActions = new ArrayList<>();
         applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(1)));
@@ -698,11 +636,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
 
         int order = 0;
         Instruction applyActionsIns = new InstructionBuilder().setOrder(order++)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(order)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(order).setInstruction(gotoTableIns(tableId)).build();
 
         ArrayList<Instruction> instructions = new ArrayList<>();
         instructions.add(applyActionsIns);
@@ -710,23 +646,16 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         instructionsBuilder.setInstruction(instructions);
 
-        MatchBuilder matchBuilder = new MatchBuilder()
-                .setEthernetMatch(ethernetMatch(null, MAC_0, null));
-        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) 3));
+        MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, MAC_0, null));
+        OrdinalFactory.EndpointFwdCtxOrdinals ord = utils.getEndpointOrdinals(endpoint);
+        addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg4.class, (long) ord.getBdId()));
         Match match = matchBuilder.build();
 
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "remoteL2", match), tableId, 70, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+        flows.createRemoteL2Flow(tableId, 70, endpoint, peerEndpoint, ipAddress, connectorId, ofWriter);
 
-        flows.createRemoteL2Flow(tableId, 70, endpointBuilder.build(), peerEndpointBuilder.build(), ipAddress,
-                connectorId, ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -737,15 +666,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_0);
         EndpointBuilder peerEndpointBuilder = buildEndpoint(IPV6_2, MAC_0, CONNECTOR_0);
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createRemoteL2Flow(tableId, 70, endpointBuilder.build(), peerEndpointBuilder.build(), ipAddress,
                 connectorId, ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -774,14 +697,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         localSubnetBuilder.setParent(L2FD_ID);
         Subnet localSubnet = localSubnetBuilder.build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, null, destSubnet, null, null, localSubnet, ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(2)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -802,14 +719,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         localSubnetBuilder.setParent(L2FD_ID);
         Subnet localSubnet = localSubnetBuilder.build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, null, destSubnet, null, null, localSubnet, ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -817,11 +728,10 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
     public void createRemoteL3RoutedFlow_incorrectPortId() {
         IpAddress ipAddress = new IpAddress(IPV4_0);
         NodeConnectorId connectorId = new NodeConnectorId(CONNECTOR_0);
-        EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1,MAC_1,CONNECTOR_0);
+        EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, CONNECTOR_0);
         endpointBuilder.setNetworkContainment(SUBNET_0);
         Endpoint endpoint = endpointBuilder.build();
 
-
         SubnetBuilder destSubnetBuilder = new SubnetBuilder();
         destSubnetBuilder.setId(SUBNET_1);
         destSubnetBuilder.setParent(L2FD_ID);
@@ -832,15 +742,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         localSubnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_1));
         Subnet localSubnet = localSubnetBuilder.build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, null, destSubnet, ipAddress, connectorId, localSubnet,
                 ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -877,11 +781,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         applyActions.add(nxLoadTunIPv4Action(IPV4_1.getValue(), false));
         applyActions.addAll(l3ApplyActions);
         Instruction applyActionsIns = new InstructionBuilder().setOrder(0)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(1)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(1).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
@@ -889,22 +791,17 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         instructionsBuilder.setInstruction(l3instructions);
 
         MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, routerMac, IPv4))
-                .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_1.getValue() + IP_PREFIX_32)).build());
+            .setLayer3Match(new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(IPV4_1.getValue() + IP_PREFIX_32))
+                .build());
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
 
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "remoteL3", match), tableId, 60, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+        flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId,
+                localSubnet, ofWriter);
 
-        flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId, localSubnet,
-                ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(eq(NODE_ID), eq(tableId), eq(flow));
     }
 
@@ -929,15 +826,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         localSubnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_1));
         Subnet localSubnet = localSubnetBuilder.build();
 
-        when(ctx.getTenant(Mockito.any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+        flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId,
+                localSubnet, ofWriter);
 
-        flows.createRemoteL3RoutedFlow(tableId, 60, endpoint, l3Address, destSubnet, ipAddress, connectorId, localSubnet,
-                ofWriter);
-        verify(ctx, times(4)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verifyZeroInteractions(ofWriter);
     }
 
@@ -959,8 +850,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         subnetBuilder.setVirtualRouterIp(new IpAddress(IPV4_0));
 
         MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, null, ARP))
-                .setLayer3Match(new ArpMatchBuilder().setArpOp(1)
-                        .setArpTargetTransportAddress(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32)).build());
+            .setLayer3Match(new ArpMatchBuilder().setArpOp(1)
+                .setArpTargetTransportAddress(new Ipv4Prefix(IPV4_0.getValue() + IP_PREFIX_32))
+                .build());
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
 
@@ -983,10 +875,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "routerarp", match), tableId, 50, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
         flows.createRouterArpFlow(50, tenant, subnetBuilder.build(), ofWriter);
 
-        verify(ctx, times(1)).getEndpointManager();
         verify(ofWriter, times(1)).writeFlow(any(NodeId.class), anyShort(), eq(flow));
     }
 
@@ -998,11 +888,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         subnetBuilder.setParent(L2FD_ID);
         subnetBuilder.setVirtualRouterIp(new IpAddress(IPV6_1));
 
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
         flows.createRouterArpFlow(50, tenant, subnetBuilder.build(), ofWriter);
 
-        verify(ctx, times(1)).getEndpointManager();
         verifyZeroInteractions(ofWriter);
     }
 
@@ -1012,21 +899,10 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         EndpointBuilder endpointBuilder = buildEndpoint(IPV4_0, MAC_1, CONNECTOR_1);
         endpointBuilder.setTenant(buildTenant().getId());
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpointBuilder.build());
 
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(1)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
-
-        MatchBuilder matchBuilder = new MatchBuilder()
-                .setEthernetMatch(new EthernetMatchBuilder()
-                        .setEthernetDestination(new EthernetDestinationBuilder().setAddress(MAC_0)
-                                .setMask(MAC_0).build())
-                        .build());
+        MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(new EthernetMatchBuilder()
+            .setEthernetDestination(new EthernetDestinationBuilder().setAddress(MAC_0).setMask(MAC_0).build()).build());
         addNxRegMatch(matchBuilder, FlowUtils.RegMatch.of(NxmNxReg5.class, (long) ordinals.getFdId()));
         Match match = matchBuilder.build();
         List<Action> actions = new ArrayList<>();
@@ -1061,10 +937,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         localSubnetBuilder.setParent(L2FD_ID);
         Subnet localSubnet = localSubnetBuilder.build();
 
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
         flows.createL3PrefixFlow(tableId, 30, gatewayEp.build(), null, tenant, localSubnet, null, ofWriter);
-        verify(ctx, times(1)).getEndpointManager();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -1094,11 +968,9 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         externalPorts.add(new NodeConnectorId(CONNECTOR_0));
         externalPorts.add(new NodeConnectorId(CONNECTOR_1));
 
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-
         flows.createL3PrefixFlow(tableId, 30, gatewayEpBuilder.build(), null, tenant, localSubnet, externalPorts,
                 ofWriter);
-        verify(ctx, times(1)).getEndpointManager();
+
         verifyZeroInteractions(ofWriter);
     }
 
@@ -1130,19 +1002,17 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         applyActions.add(nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(1)));
         applyActions.addAll(l3ApplyActions);
         Instruction applyActionsIns = new InstructionBuilder().setOrder(0)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(1)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(1).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         instructionsBuilder.setInstruction(l3instructions);
 
-        MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null,
-                DestinationMapper.ROUTER_MAC, IPv4));
+        MatchBuilder matchBuilder =
+                new MatchBuilder().setEthernetMatch(ethernetMatch(null, DestinationMapper.ROUTER_MAC, IPv4));
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
 
@@ -1150,15 +1020,8 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "L3prefix", match), tableId, 30 + prefixLength, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
+        flows.createL3PrefixFlow(tableId, 30, gatewayEp.build(), l3Prefix, tenant, localSubnet, null, ofWriter);
 
-        flows.createL3PrefixFlow(tableId, 30, gatewayEp.build(), l3Prefix, tenant, localSubnet, null,
-                ofWriter);
-        verify(ctx, times(3)).getTenant(any(TenantId.class));
-        verify(ctx, times(2)).getEndpointManager();
-        verify(ctx, times(1)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(any(NodeId.class), anyShort(), eq(flow));
     }
 
@@ -1204,19 +1067,17 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         applyActions.add(nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(0)));
         applyActions.addAll(l3ApplyActions);
         Instruction applyActionsIns = new InstructionBuilder().setOrder(0)
-                .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
-                .build();
-        Instruction gotoTable = new InstructionBuilder().setOrder(1)
-                .setInstruction(gotoTableIns(tableId))
-                .build();
+            .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()])))
+            .build();
+        Instruction gotoTable = new InstructionBuilder().setOrder(1).setInstruction(gotoTableIns(tableId)).build();
         ArrayList<Instruction> l3instructions = new ArrayList<>();
         l3instructions.add(applyActionsIns);
         l3instructions.add(gotoTable);
         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
         instructionsBuilder.setInstruction(l3instructions);
 
-        MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null,
-                DestinationMapper.ROUTER_MAC, IPv6));
+        MatchBuilder matchBuilder =
+                new MatchBuilder().setEthernetMatch(ethernetMatch(null, DestinationMapper.ROUTER_MAC, IPv6));
         addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) 5));
         Match match = matchBuilder.build();
 
@@ -1224,23 +1085,10 @@ public class DestinationMapperFlowsTest extends MapperUtilsTest {
         Flow flow = buildFlow(FlowIdUtils.newFlowId(tableId, "L3prefix", match), tableId, 30 + prefixLength, match,
                 instructionsBuilder.build()).build();
 
-        when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant());
-        when(ctx.getEndpointManager()).thenReturn(endpointManager);
-        when(ctx.getCurrentPolicy()).thenReturn(policyInfo);
-
         flows.createL3PrefixFlow(tableId, 30, gatewayEpBuilder.build(), l3Prefix, tenant, localSubnet, externalPorts,
                 ofWriter);
 
-        verify(ctx, times(6)).getTenant(any(TenantId.class));
-        verify(ctx, times(3)).getEndpointManager();
-        verify(ctx, times(2)).getCurrentPolicy();
         verify(ofWriter, times(1)).writeFlow(any(NodeId.class), anyShort(), eq(flow));
     }
 
-    private void resetPolicyOrdinalCounterValue() throws  Exception {
-        // TODO find better way, maybe fixed test method order?
-        Field field = OrdinalFactory.class.getDeclaredField("policyOrdinal");
-        field.setAccessible(true);
-        field.set(null, new AtomicInteger(1));
-    }
-}
\ No newline at end of file
+}