Fix of NPEs and attempt to fix Neutron mapper. 34/20334/3
authorKeith Burns (alagalah) <alagalah@gmail.com>
Thu, 14 May 2015 02:07:38 +0000 (19:07 -0700)
committerKeith Burns (alagalah) <alagalah@gmail.com>
Thu, 14 May 2015 13:58:11 +0000 (06:58 -0700)
- Added utilities to only put Switch in READY when Endpoints attached.

- Also removes switch from ready when last EP is removed.
  This means we don't write and handle all OF switches connected to
  controller unless an EP is present. It means we play better with others.

Change-Id: I3b3e66259e2e43a201d298dd8af523cc5a3cf426
Signed-off-by: Keith Burns (alagalah) <alagalah@gmail.com>
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/EndpointManager.java
renderers/ofoverlay/src/main/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/node/SwitchManager.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/DestinationMapperTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/GroupTableTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/PortSecurityTest.java
renderers/ofoverlay/src/test/java/org/opendaylight/groupbasedpolicy/renderer/ofoverlay/flow/SourceMapperTest.java

index 551f6e7278eebfd998251e117bd70b54a21e7389..c149921b882e17ef5cff9ca050c1416121e46d87 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014 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,
@@ -76,33 +76,26 @@ import com.google.common.collect.Sets;
  * their locations for renderering. The endpoint manager will maintain
  * appropriate indexes only for switches that are attached to the current
  * controller node.
- *
  * In order to render the policy, we need to be able to efficiently enumerate
  * all endpoints on a particular switch and also all the switches containing
  * each particular endpoint group
  *
  * @author readams
  */
-public class EndpointManager implements AutoCloseable, DataChangeListener
-{
-    private static final Logger LOG =
-            LoggerFactory.getLogger(EndpointManager.class);
-    private final static InstanceIdentifier<Nodes> nodesIid = InstanceIdentifier
-            .builder(Nodes.class).build();
-    private static final InstanceIdentifier<Endpoint> endpointsIid =
-            InstanceIdentifier.builder(Endpoints.class)
-                    .child(Endpoint.class).build();
+public class EndpointManager implements AutoCloseable, DataChangeListener {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EndpointManager.class);
+    private final static InstanceIdentifier<Nodes> nodesIid = InstanceIdentifier.builder(Nodes.class).build();
+    private static final InstanceIdentifier<Endpoint> endpointsIid = InstanceIdentifier.builder(Endpoints.class)
+        .child(Endpoint.class)
+        .build();
     final ListenerRegistration<DataChangeListener> listenerReg;
 
-    private final ConcurrentHashMap<EpKey, Endpoint> endpoints =
-            new ConcurrentHashMap<>();
-    private final ConcurrentHashMap<NodeId, ConcurrentMap<EgKey, Set<EpKey>>> endpointsByGroupByNode =
-            new ConcurrentHashMap<>();
-    private final ConcurrentHashMap<NodeId, Set<EpKey>> endpointsByNode =
-            new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<EpKey, Endpoint> endpoints = new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<NodeId, ConcurrentMap<EgKey, Set<EpKey>>> endpointsByGroupByNode = new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<NodeId, Set<EpKey>> endpointsByNode = new ConcurrentHashMap<>();
 
-    private final ConcurrentHashMap<EgKey, Set<EpKey>> endpointsByGroup =
-            new ConcurrentHashMap<>();
+    private final ConcurrentHashMap<EgKey, Set<EpKey>> endpointsByGroup = new ConcurrentHashMap<>();
 
     private List<EndpointListener> listeners = new CopyOnWriteArrayList<>();
 
@@ -112,19 +105,14 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
 
     final private DataBroker dataProvider;
 
-    public EndpointManager(DataBroker dataProvider,
-            RpcProviderRegistry rpcRegistry,
-            ScheduledExecutorService executor,
+    public EndpointManager(DataBroker dataProvider, RpcProviderRegistry rpcRegistry, ScheduledExecutorService executor,
             SwitchManager switchManager) {
         this.executor = executor;
         this.dataProvider = dataProvider;
         EndpointRpcRegistry.register(dataProvider, rpcRegistry, endpointRpcAug);
         if (dataProvider != null) {
-            listenerReg = dataProvider
-                    .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                            endpointsIid,
-                            this,
-                            DataChangeScope.ONE);
+            listenerReg = dataProvider.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, endpointsIid, this,
+                    DataChangeScope.ONE);
         } else
             listenerReg = null;
 
@@ -139,7 +127,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * Add a {@link EndpointListener} to get notifications of switch events
      *
      * @param listener
-     *            the {@link EndpointListener} to add
+     *        the {@link EndpointListener} to add
      */
     public void registerListener(EndpointListener listener) {
         listeners.add(listener);
@@ -149,7 +137,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * Get a collection of endpoints attached to a particular switch
      *
      * @param nodeId
-     *            the nodeId of the switch to get endpoints for
+     *        the nodeId of the switch to get endpoints for
      * @return a collection of {@link Endpoint} objects.
      */
     public synchronized Set<EgKey> getGroupsForNode(NodeId nodeId) {
@@ -163,30 +151,28 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * Get the set of nodes
      *
      * @param egKey
-     *            the egKey of the endpointgroup to get nodes for
+     *        the egKey of the endpointgroup to get nodes for
      * @return a collection of {@link NodeId} objects.
      */
     public synchronized Set<NodeId> getNodesForGroup(final EgKey egKey) {
-        return ImmutableSet.copyOf(Sets.filter(endpointsByGroupByNode.keySet(),
-                new Predicate<NodeId>() {
-                    @Override
-                    public boolean apply(NodeId input) {
-                        Map<EgKey, Set<EpKey>> nodeEps =
-                                endpointsByGroupByNode.get(input);
-                        return (nodeEps != null &&
-                        nodeEps.containsKey(egKey));
-                    }
+        return ImmutableSet.copyOf(Sets.filter(endpointsByGroupByNode.keySet(), new Predicate<NodeId>() {
 
-                }));
+            @Override
+            public boolean apply(NodeId input) {
+                Map<EgKey, Set<EpKey>> nodeEps = endpointsByGroupByNode.get(input);
+                return (nodeEps != null && nodeEps.containsKey(egKey));
+            }
+
+        }));
     }
 
     /**
      * Get the endpoints in a particular group on a particular node
      *
      * @param nodeId
-     *            the node ID to look up
+     *        the node ID to look up
      * @param eg
-     *            the group to look up
+     *        the group to look up
      * @return the endpoints
      */
     public synchronized Collection<Endpoint> getEndpointsForNode(NodeId nodeId, EgKey eg) {
@@ -199,14 +185,14 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
         Collection<EpKey> ebn = nodeEps.get(eg);
         if (ebn == null)
             return Collections.emptyList();
-        return ImmutableList.copyOf(Collections2.transform(ebn,indexTransform));
+        return ImmutableList.copyOf(Collections2.transform(ebn, indexTransform));
     }
 
     /**
      * Get the endpoints on a particular node
      *
      * @param nodeId
-     *            the node ID to look up
+     *        the node ID to look up
      * @return the endpoints
      */
     public synchronized Collection<Endpoint> getEndpointsForNode(final NodeId nodeId) {
@@ -224,7 +210,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * Get the endpoint object for the given key
      *
      * @param epKey
-     *            the key
+     *        the key
      * @return the {@link Endpoint} corresponding to the key
      */
     public Endpoint getEndpoint(EpKey epKey) {
@@ -235,7 +221,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * Set the learning mode to the specified value
      *
      * @param learningMode
-     *            the learning mode to set
+     *        the learning mode to set
      */
     public void setLearningMode(LearningMode learningMode) {
         // No-op for now
@@ -245,7 +231,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * Get a collection of endpoints in a particular endpoint group
      *
      * @param eg
-     *            endpoint group ID
+     *        endpoint group ID
      * @return a collection of {@link Endpoint} objects.
      */
     public synchronized Collection<Endpoint> getEndpointsForGroup(EgKey eg) {
@@ -261,7 +247,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
      * directly represented in the endpoint object
      *
      * @param endpoint
-     *            the {@link Endpoint} to resolve
+     *        the {@link Endpoint} to resolve
      * @return the list of {@link ConditionName}
      */
     public List<ConditionName> getCondsForEndpoint(Endpoint endpoint) {
@@ -333,17 +319,16 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
 
                 Optional<Nodes> result;
                 try {
-                    result = dataProvider
-                            .newReadOnlyTransaction().read(
-                                    LogicalDatastoreType.OPERATIONAL, nodesIid).get();
+                    result = dataProvider.newReadOnlyTransaction()
+                        .read(LogicalDatastoreType.OPERATIONAL, nodesIid)
+                        .get();
                     if (result.isPresent()) {
                         Nodes nodes = result.get();
                         for (Node node : nodes.getNode()) {
                             if (node.getNodeConnector() != null) {
                                 boolean found = false;
                                 for (NodeConnector nc : node.getNodeConnector()) {
-                                    FlowCapableNodeConnector fcnc = nc
-                                            .getAugmentation(FlowCapableNodeConnector.class);
+                                    FlowCapableNodeConnector fcnc = nc.getAugmentation(FlowCapableNodeConnector.class);
                                     if (fcnc.getName().equals(portName)) {
                                         nodeInfo = new NodeInfo();
                                         nodeInfo.setNode(node);
@@ -426,25 +411,24 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
         }
     }
 
-    private Function<EpKey, Endpoint> indexTransform =
-            new Function<EpKey, Endpoint>() {
-                @Override
-                public Endpoint apply(EpKey input) {
-                    return endpoints.get(input);
-                }
-            };
+    private Function<EpKey, Endpoint> indexTransform = new Function<EpKey, Endpoint>() {
+
+        @Override
+        public Endpoint apply(EpKey input) {
+            return endpoints.get(input);
+        }
+    };
 
     private boolean validEp(Endpoint endpoint) {
-        return (endpoint != null && endpoint.getTenant() != null &&
-                (endpoint.getEndpointGroup() != null || endpoint.getEndpointGroups() != null) &&
-                endpoint.getL2Context() != null && endpoint.getMacAddress() != null);
+        return (endpoint != null && endpoint.getTenant() != null
+                && (endpoint.getEndpointGroup() != null || endpoint.getEndpointGroups() != null)
+                && endpoint.getL2Context() != null && endpoint.getMacAddress() != null);
     }
 
     private NodeId getLocation(Endpoint endpoint) {
         if (!validEp(endpoint))
             return null;
-        OfOverlayContext context =
-                endpoint.getAugmentation(OfOverlayContext.class);
+        OfOverlayContext context = endpoint.getAugmentation(OfOverlayContext.class);
         if (context != null)
             return context.getNodeId();
 
@@ -481,16 +465,14 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
         ConcurrentMap<EgKey, Set<EpKey>> map = endpointsByGroupByNode.get(location);
         if (map == null) {
             map = new ConcurrentHashMap<>();
-            ConcurrentMap<EgKey, Set<EpKey>> old =
-                    endpointsByGroupByNode.putIfAbsent(location, map);
+            ConcurrentMap<EgKey, Set<EpKey>> old = endpointsByGroupByNode.putIfAbsent(location, map);
             if (old != null)
                 map = old;
         }
         return SetUtils.getNestedSet(eg, map);
     }
 
-    private static final ConcurrentMap<EgKey, Set<EpKey>> EMPTY_MAP =
-            new ConcurrentHashMap<>();
+    private static final ConcurrentMap<EgKey, Set<EpKey>> EMPTY_MAP = new ConcurrentHashMap<>();
 
     private Set<EpKey> getEpGSet(EgKey eg) {
         return SetUtils.getNestedSet(eg, endpointsByGroup);
@@ -570,6 +552,8 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
                 Set<EpKey> epsNode = new HashSet<EpKey>();
                 epsNode.add(newEpKey);
                 endpointsByNode.put(newLoc, epsNode);
+                SwitchManager.activateEndpoint(newLoc);
+
             } else {
                 Set<EpKey> epsNode = endpointsByNode.get(newLoc);
                 epsNode.add(newEpKey);
@@ -603,14 +587,15 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
             Set<EpKey> epsNode = endpointsByNode.get(oldLoc);
             if (epsNode != null) {
                 epsNode.remove(oldEpKey);
-                if (epsNode.isEmpty())
+                if (epsNode.isEmpty()) {
                     endpointsByNode.remove(oldLoc);
+                    SwitchManager.deactivateEndpoint(oldLoc);
+                }
             }
             // Update endpointsByGroupByNode
             // Update endpointsByGroup
             // Get map of EPGs and their Endpoints for Node
-            ConcurrentMap<EgKey, Set<EpKey>> map =
-                    endpointsByGroupByNode.get(oldLoc);
+            ConcurrentMap<EgKey, Set<EpKey>> map = endpointsByGroupByNode.get(oldLoc);
             // For each EPG in the removed endpoint...
             for (EndpointGroupId oldEpgId : newEpgIds) {
                 EgKey oldEgKey = new EgKey(oldEp.getTenant(), oldEpgId);
@@ -641,8 +626,8 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
         /*
          * Moved endpoint (from node to node or from NULL to node)
          */
-        if ((oldEp != null && newEp != null && oldEpKey != null && newEpKey != null) &&
-                (oldEpKey.toString().equals(newEpKey.toString()))) {
+        if ((oldEp != null && newEp != null && oldEpKey != null && newEpKey != null)
+                && (oldEpKey.toString().equals(newEpKey.toString()))) {
             // old and new Endpoints have same key. (same endpoint)
 
             /*
@@ -653,13 +638,14 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
                 Set<EpKey> epsNode = endpointsByNode.get(oldLoc);
                 if (epsNode != null) {
                     epsNode.remove(oldEpKey);
-                    if (epsNode.isEmpty())
+                    if (epsNode.isEmpty()) {
                         endpointsByNode.remove(oldLoc);
+                        SwitchManager.deactivateEndpoint(oldLoc);
+                    }
                 }
                 // Update endpointsByGroupByNode
                 // Get map of EPGs and their Endpoints for Node
-                ConcurrentMap<EgKey, Set<EpKey>> map =
-                        endpointsByGroupByNode.get(oldLoc);
+                ConcurrentMap<EgKey, Set<EpKey>> map = endpointsByGroupByNode.get(oldLoc);
                 // For each EPG in the removed endpoint...
                 for (EndpointGroupId oldEpgId : oldEpgIds) {
                     EgKey oldEgKey = new EgKey(oldEp.getTenant(), oldEpgId);
@@ -673,8 +659,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
                     }
                     // endpointsByGroup
                     Set<EpKey> geps = endpointsByGroup.get(oldEgKey);
-                    if (geps != null)
-                    {
+                    if (geps != null) {
                         geps.remove(oldEpKey);
                         if (geps.isEmpty())
                             endpointsByGroup.remove(oldEgKey);
@@ -696,6 +681,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
                 Set<EpKey> newEpsNode = new HashSet<EpKey>();
                 newEpsNode.add(newEpKey);
                 endpointsByNode.put(newLoc, newEpsNode);
+                SwitchManager.activateEndpoint(newLoc);
             } else {
                 Set<EpKey> newEpsNode = endpointsByNode.get(newLoc);
                 newEpsNode.add(newEpKey);
@@ -747,6 +733,7 @@ public class EndpointManager implements AutoCloseable, DataChangeListener
     // A wrapper class around node, nodeConnector info so we can pass a final
     // object inside OnSuccess anonymous inner class
     private static class NodeInfo {
+
         NodeConnector nodeConnector;
         Node node;
 
index 5b571ba944a9ce40e070f35442a47bce386a9a2c..f3b39c3e19609fc87dc765a7798ca6efeb7d8068 100644 (file)
@@ -58,7 +58,7 @@ public class SwitchManager implements AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(SwitchManager.class);
 
-    protected Map<NodeId, SwitchState> switches = new HashMap<>();
+    protected static Map<NodeId, SwitchState> switches = new HashMap<>();
     protected List<SwitchListener> listeners = new CopyOnWriteArrayList<>();
 
     private final FlowCapableNodeListener nodeListener;
@@ -81,6 +81,18 @@ public class SwitchManager implements AutoCloseable {
         LOG.debug("Initialized OFOverlay switch manager");
     }
 
+    // When first endpoint is attached to switch, it can be ready
+    public static void activateEndpoint(NodeId nodeId) {
+        switches.get(nodeId).hasEndpoints=true;
+        switches.get(nodeId).updateStatus();
+    }
+
+    // When last endpoint is removed from switch, it is no longer ready
+    public static void deactivateEndpoint(NodeId nodeId) {
+        switches.get(nodeId).hasEndpoints=false;
+        switches.get(nodeId).updateStatus();
+    }
+
     /**
      * Get the collection of switches that are in the "ready" state. Note
      * that the collection is immutable.
@@ -115,7 +127,7 @@ public class SwitchManager implements AutoCloseable {
         return ImmutableSet.copyOf(state.externalPorts);
     }
 
-    public synchronized NodeConnectorId getTunnelPort(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
+    public static synchronized NodeConnectorId getTunnelPort(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
         SwitchState state = switches.get(nodeId);
         if (state == null) {
             return null;
@@ -127,7 +139,7 @@ public class SwitchManager implements AutoCloseable {
         return tunnel.getNodeConnectorId();
     }
 
-    public synchronized IpAddress getTunnelIP(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
+    public static synchronized IpAddress getTunnelIP(NodeId nodeId, Class<? extends TunnelTypeBase> tunnelType) {
         SwitchState state = switches.get(nodeId);
         if (state == null) {
             return null;
@@ -242,6 +254,7 @@ public class SwitchManager implements AutoCloseable {
         private FlowCapableNode fcNode;
         private OfOverlayNodeConfig nodeConfig;
         private Map<InstanceIdentifier<NodeConnector>, FlowCapableNodeConnector> fcncByNcIid = Maps.newHashMap();
+        private boolean hasEndpoints=false;
 
         Map<Class<? extends TunnelTypeBase>, TunnelBuilder> tunnelBuilderByType = new HashMap<>();
         Set<NodeConnectorId> externalPorts = new HashSet<>();
@@ -314,7 +327,7 @@ public class SwitchManager implements AutoCloseable {
         private void updateStatus() {
             boolean tunnelWithIpAndNcExists = tunnelWithIpAndNcExists();
             if (fcNode != null) {
-                if (tunnelWithIpAndNcExists) {
+                if (tunnelWithIpAndNcExists && hasEndpoints) {
                     setStatus(SwitchStatus.READY);
                 } else {
                     setStatus(SwitchStatus.PREPARING);
@@ -340,12 +353,14 @@ public class SwitchManager implements AutoCloseable {
             LOG.trace("Iterating over tunnel till tunnel with IP and node-connector is not found.");
             for (TunnelBuilder tb : tunnelBuilderByType.values()) {
                 if (tb.getIp() != null && tb.getNodeConnectorId() != null) {
-                    LOG.trace("Tunnel found. Type: {} IP: {} Port: {} Node-connector: {}", tb.getTunnelType()
-                        .getSimpleName(), tb.getIp(), tb.getPort(), tb.getNodeConnectorId());
+//                    LOG.trace("Tunnel found. Type: {} IP: {} Port: {} Node-connector: {}", tb.getTunnelType()
+//                        .getSimpleName(), tb.getIp(), tb.getPort(), tb.getNodeConnectorId());
+                    LOG.trace("Tunnel found.");
                     return true;
                 } else {
-                    LOG.trace("Tunnel which is not completed: Type: {} IP: {} Port: {} Node-connector: {}",
-                            tb.getTunnelType().getSimpleName(), tb.getIp(), tb.getPort(), tb.getNodeConnectorId());
+//                    LOG.trace("Tunnel which is not completed: Type: {} IP: {} Port: {} Node-connector: {}",
+//                            tb.getTunnelType().getSimpleName(), tb.getIp(), tb.getPort(), tb.getNodeConnectorId());
+                    LOG.trace("Tunnel which is not completed");
                 }
             }
             return false;
index a50eabc7e132c09099bf1e8ea0697c00ebe3a64c..7753379cf4d3335941ab27f4b0558b259950e69e 100755 (executable)
@@ -265,11 +265,12 @@ public class DestinationMapperTest extends FlowTableTest {
 \r
     @Test\r
     public void testSame() throws Exception {\r
+        addSwitches();\r
         Endpoint localEp = localEP().build();\r
         endpointManager.addEndpoint(localEp);\r
         Endpoint remoteEp = remoteEP(remoteNodeId).build();\r
         endpointManager.addEndpoint(remoteEp);\r
-        addSwitches();\r
+\r
 \r
         policyResolver.addTenant(baseTenant().setContract(\r
                 ImmutableList.<Contract> of(baseContract(null).build())).build());\r
@@ -278,13 +279,13 @@ public class DestinationMapperTest extends FlowTableTest {
 \r
     @Test\r
     public void testDiff() throws Exception {\r
+        addSwitches();\r
         Endpoint localEp = localEP().build();\r
         endpointManager.addEndpoint(localEp);\r
         Endpoint remoteEp = remoteEP(remoteNodeId)\r
                 .setEndpointGroup(eg2)\r
                 .build();\r
         endpointManager.addEndpoint(remoteEp);\r
-        addSwitches();\r
 \r
         policyResolver.addTenant(baseTenant().setContract(\r
                 ImmutableList.<Contract> of(baseContract(null).build())).build());\r
index b3244c0d02236dbc6717c863fb12115c8bb2c9ef..b6aa97e0b94145e4d6eaad004c713b53a6f3aa88 100755 (executable)
@@ -20,6 +20,7 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.GroupTable.Buck
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.GroupTable.GroupCtx;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayNodeConfigBuilder;\r
@@ -43,6 +44,7 @@ public class GroupTableTest extends OfTableTest {
             new NodeConnectorId(nodeId.getValue() + ":42");\r
     NodeConnectorId remoteTunnelId =\r
             new NodeConnectorId(remoteNodeId.getValue() + ":101");\r
+    PortNumber portNumber = new PortNumber(4789);\r
 \r
     @Before\r
     public void setup() throws Exception {\r
@@ -52,19 +54,17 @@ public class GroupTableTest extends OfTableTest {
 \r
     @Test\r
     public void testGroup() throws Exception {\r
-        Endpoint localEp = localEP().build();\r
-        endpointManager.addEndpoint(localEp);\r
-        Endpoint remoteEp = remoteEP(remoteNodeId).build();\r
-        endpointManager.addEndpoint(remoteEp);\r
         switchManager.addSwitch(\r
                 nodeId,\r
                 tunnelId,\r
                 Collections.<NodeConnectorId>emptySet(),\r
                 new OfOverlayNodeConfigBuilder().setTunnel(\r
-                        ImmutableList.of(new TunnelBuilder().setIp(new IpAddress(new Ipv4Address("1.2.3.4")))\r
-                            .setTunnelType(TunnelTypeVxlan.class)\r
-                            .setNodeConnectorId(tunnelId)\r
-                            .build())).build());\r
+                        ImmutableList.of(new TunnelBuilder()\r
+                                            .setIp(new IpAddress(new Ipv4Address("1.2.3.4")))\r
+                                            .setTunnelType(TunnelTypeVxlan.class)\r
+                                            .setNodeConnectorId(tunnelId)\r
+                                            .setPort(portNumber)\r
+                                            .build())).build());\r
         switchManager.addSwitch(\r
                 remoteNodeId,\r
                 remoteTunnelId,\r
@@ -73,7 +73,13 @@ public class GroupTableTest extends OfTableTest {
                         ImmutableList.of(new TunnelBuilder().setIp(new IpAddress(new Ipv4Address("1.2.3.5")))\r
                             .setTunnelType(TunnelTypeVxlan.class)\r
                             .setNodeConnectorId(tunnelId)\r
+                            .setPort(portNumber)\r
                             .build())).build());\r
+        Endpoint localEp = localEP().build();\r
+        endpointManager.addEndpoint(localEp);\r
+        Endpoint remoteEp = remoteEP(remoteNodeId).build();\r
+        endpointManager.addEndpoint(remoteEp);\r
+\r
 \r
         policyResolver.addTenant(baseTenant().setContract(\r
                 ImmutableList.<Contract>of(baseContract(null).build())).build());\r
index 38103e02f6b8cb442e3ff60c88f1275677a6f56c..3fecbf76036df7dbab1d78efb0a3ec9494fc8339 100755 (executable)
@@ -62,7 +62,7 @@ public class PortSecurityTest extends FlowTableTest {
         for (Flow f : fm.getTableForNode(nodeId, (short) 0).getFlow()) {\r
             flowMap.put(f.getId().getValue(), f);\r
             Long etherType = null;\r
-            if (f.getMatch() != null) {\r
+            if (f.getMatch() != null && f.getMatch().getEthernetMatch() !=null) {\r
                 etherType = f.getMatch().getEthernetMatch().getEthernetType().getType().getValue();\r
             }\r
             if (f.getMatch() == null || FlowUtils.ARP.equals(etherType) || FlowUtils.IPv4.equals(etherType)\r
index 6aff6711ec12a33b3342d8c91cbed9b03c44b326..bf74b6b12fcfc94772b2dabc8c72891a98b891d4 100755 (executable)
@@ -9,6 +9,7 @@
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;\r
 \r
 import java.math.BigInteger;\r
+import java.util.Collections;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Objects;\r
@@ -19,6 +20,8 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.FlowMa
 import org.opendaylight.groupbasedpolicy.resolver.ConditionGroup;\r
 import org.opendaylight.groupbasedpolicy.resolver.EgKey;\r
 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\r
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;\r
@@ -26,11 +29,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayNodeConfigBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.nodes.node.TunnelBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.overlay.rev150105.TunnelTypeVxlan;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
@@ -59,12 +66,21 @@ public class SourceMapperTest extends FlowTableTest {
 \r
     @Test\r
     public void testMap() throws Exception {\r
+        switchManager.addSwitch(\r
+                nodeId,\r
+                tunnelId,\r
+                Collections.<NodeConnectorId>emptySet(),\r
+                new OfOverlayNodeConfigBuilder().setTunnel(\r
+                        ImmutableList.of(new TunnelBuilder().setIp(new IpAddress(new Ipv4Address("1.2.3.4")))\r
+                            .setTunnelType(TunnelTypeVxlan.class)\r
+                            .setNodeConnectorId(tunnelId)\r
+                            .build())).build());\r
         Endpoint ep = localEP().build();\r
         endpointManager.addEndpoint(ep);\r
         policyResolver.addTenant(baseTenant().build());\r
 \r
         FlowMap fm = dosync(null);\r
-        assertEquals(2, fm.getTableForNode(nodeId, (short) 1).getFlow().size());\r
+        assertEquals(4, fm.getTableForNode(nodeId, (short) 1).getFlow().size());\r
 \r
         int count = 0;\r
         HashMap<String, Flow> flowMap = new HashMap<>();\r
@@ -73,10 +89,11 @@ public class SourceMapperTest extends FlowTableTest {
             if (f.getMatch() == null) {\r
                 assertEquals(FlowUtils.dropInstructions(), f.getInstructions());\r
                 count += 1;\r
-            } else if (Objects.equals(ep.getMacAddress(), f.getMatch()\r
+            } else if ((f.getMatch() !=null && f.getMatch().getEthernetMatch() != null)\r
+             && (Objects.equals(ep.getMacAddress(), f.getMatch()\r
                 .getEthernetMatch()\r
                 .getEthernetSource()\r
-                .getAddress())) {\r
+                .getAddress()))) {\r
                 PolicyInfo pi = policyResolver.getCurrentPolicy();\r
                 List<ConditionName> cset = endpointManager.getCondsForEndpoint(ep);\r
                 ConditionGroup cg = pi.getEgCondGroup(new EgKey(tid, eg), cset);\r