fix registerEndpoint in port delete for base Eps 13/62913/2
authorMichal Cmarada <mcmarada@cisco.com>
Mon, 11 Sep 2017 06:45:55 +0000 (08:45 +0200)
committerMichal Cmarada <mcmarada@cisco.com>
Mon, 11 Sep 2017 06:47:42 +0000 (08:47 +0200)
when neutron router interface is deleted, contextId
should be changed back to NetworkId. this patch fixes
NetworkId for parents in L2 endpoint.

Change-Id: I799fd4fb6c9a79b68514e7c139cc09b6c2e279fa
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/EndpointRegistrator.java
neutron-mapper/src/main/java/org/opendaylight/groupbasedpolicy/neutron/mapper/mapping/NeutronPortAware.java
renderers/vpp/src/main/java/org/opendaylight/groupbasedpolicy/renderer/vpp/util/GbpNetconfTransaction.java

index 0a95f3fc1aea7a9070d308a06bd41693279d212f..551a84357c4b93e3a74884a6fba1ca0684cd9e2f 100644 (file)
@@ -61,7 +61,7 @@ public class EndpointRegistrator {
         try {
             RpcResult<Void> rpcResult = baseEpService.registerEndpoint(regBaseEpInput).get();
             if (!rpcResult.isSuccessful()) {
-                LOG.warn("Illegal state - registerEndpoint was not successful. Input of RPC: {}", regBaseEpInput);
+                LOG.warn("Illegal state - register Base Endpoint was not successful. Input of RPC: {}", regBaseEpInput);
                 return false;
             }
             return true;
@@ -97,7 +97,7 @@ public class EndpointRegistrator {
         try {
             RpcResult<Void> rpcResult = epService.registerEndpoint(regEndpointInput).get();
             if (!rpcResult.isSuccessful()) {
-                LOG.warn("Illegal state - registerEndpoint was not successful. Input of RPC: {}", regEndpointInput);
+                LOG.warn("Illegal state - register Endpoint was not successful. Input of RPC: {}", regEndpointInput);
                 return false;
             }
             return true;
index 7901f8f1d229208d3487c3f8fa4a96be9cee6b7e..951d593855cb71a5ea6100032871f10f74492419 100644 (file)
@@ -377,8 +377,7 @@ public class NeutronPortAware implements NeutronAware<Port> {
                             createBasicMacAddrEpInputBuilder(portInSameSubnet, networkContainment, endpointGroupIds);
                     AddressEndpointRegBuilder l3BaseEp = createBasicL3AddrEpInputBuilder(portInSameSubnet,
                             networkContainment, endpointGroupIds, neutron);
-                    ContextId resolvedCtxId = l3BaseEp.getContextId();
-                    ContextId networkCtxId = new ContextId(portInSameSubnet.getNetworkId().getValue());
+
                     setParentChildRelationshipForEndpoints(l3BaseEp, l2BaseEp);
                     AddressEndpointUnregBuilder addrEpUnreg =
                             new AddressEndpointUnregBuilder().setAddress(l3BaseEp.getAddress())
@@ -395,6 +394,7 @@ public class NeutronPortAware implements NeutronAware<Port> {
                     } else {
                         l3BaseEp.setContextId(new ContextId(networkId.getValue()));
                     }
+                    setParentChildRelationshipForEndpoints(l3BaseEp, l2BaseEp);
                     RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder()
                         .setAddressEndpointReg(ImmutableList.of(l2BaseEp.build(), l3BaseEp.build())).build();
                     epRegistrator.registerEndpoint(regBaseEpInput);
index 42aaab4006fac476e852330a87078a2540837a5d..c6c461833fa48ac3a061034d283513c9d9be74e3 100644 (file)
@@ -53,7 +53,8 @@ public class GbpNetconfTransaction {
     public static <T extends DataObject> boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid,
         @Nonnull final InstanceIdentifier<T> iid, @Nonnull final T data, byte retryCounter) {
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
-        boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), iid, data, retryCounter);
+        boolean result =
+            write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), iid, data, retryCounter);
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
         return result;
     }
@@ -76,9 +77,10 @@ public class GbpNetconfTransaction {
      * @return true if transaction is successful, false otherwise
      */
     public static <T extends DataObject> boolean netconfSyncedMerge(@Nonnull final InstanceIdentifier<Node> vppIid,
-                                                                    @Nonnull final InstanceIdentifier<T> iid, @Nonnull final T data, byte retryCounter) {
+        @Nonnull final InstanceIdentifier<T> iid, @Nonnull final T data, byte retryCounter) {
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
-        boolean result = merge(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), iid, data, retryCounter);
+        boolean result =
+            merge(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), iid, data, retryCounter);
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
         return result;
     }
@@ -90,8 +92,8 @@ public class GbpNetconfTransaction {
      * @param retryCounter  retry counter, will repeat the operation for specified amount of times if transaction fails
      * @return true if transaction is successful, false otherwise
      */
-    public static boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid, @Nonnull final ConfigCommand command,
-        byte retryCounter) {
+    public static boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid,
+        @Nonnull final ConfigCommand command, byte retryCounter) {
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
         boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), command, retryCounter);
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
@@ -105,8 +107,8 @@ public class GbpNetconfTransaction {
      * @param retryCounter  retry counter, will repeat the operation for specified amount of times if transaction fails
      * @return true if transaction is successful, false otherwise
      */
-    public static boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid, @Nonnull final RoutingCommand command,
-        byte retryCounter) {
+    public static boolean netconfSyncedWrite(@Nonnull final InstanceIdentifier<Node> vppIid,
+        @Nonnull final RoutingCommand command, byte retryCounter) {
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().lock();
         boolean result = write(VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey(), command, retryCounter);
         VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getValue().unlock();
@@ -271,13 +273,10 @@ public class GbpNetconfTransaction {
         Preconditions.checkArgument(!data.isEmpty());
         final ReadWriteTransaction rwTx = mountpoint.newReadWriteTransaction();
         try {
-            data.forEach((k, v) -> {
-                rwTx.put(LogicalDatastoreType.CONFIGURATION, k, v, true);
-            });
+            data.forEach((k, v) -> rwTx.put(LogicalDatastoreType.CONFIGURATION, k, v, true));
             final CheckedFuture<Void, TransactionCommitFailedException> futureTask = rwTx.submit();
             futureTask.get();
-            LOG.trace("Netconf WRITE transaction done for {}",
-                    data.keySet().stream().map(iid -> iid.getPathArguments()));
+            LOG.trace("Netconf WRITE transaction done for {}", data);
             return true;
         } catch (Exception e) {
             // Retry
@@ -334,7 +333,8 @@ public class GbpNetconfTransaction {
      * @param retryCounter number of attempts
      * @return true if transaction is successful, false otherwise
      */
-    private static boolean deleteIfExists(final InstanceIdentifier<Node> vppIid, final AbstractInterfaceCommand command, byte retryCounter) {
+    private static boolean deleteIfExists(final InstanceIdentifier<Node> vppIid, final AbstractInterfaceCommand command,
+        byte retryCounter) {
         Preconditions.checkNotNull(vppIid);
         InstanceIdentifier<Interface> iid = VppIidFactory.getInterfaceIID(command.getInterfaceBuilder().getKey());
         return deleteIfExists(vppIid, iid, retryCounter);
@@ -383,7 +383,8 @@ public class GbpNetconfTransaction {
             final Set<InstanceIdentifier<T>> iids, byte retryCounter) {
         LOG.trace("Netconf DELETE transaction started. Data will be read at first. RetryCounter: {}", retryCounter);
         Preconditions.checkNotNull(vppIid);
-        final ReadWriteTransaction rwTx = VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey().newReadWriteTransaction();
+        final ReadWriteTransaction rwTx =
+            VbdNetconfTransaction.NODE_DATA_BROKER_MAP.get(vppIid).getKey().newReadWriteTransaction();
         Set<InstanceIdentifier<T>> alreadyRemoved = new HashSet<>();
         for (InstanceIdentifier<T> iid : iids) {
             short microReadRetries = 3;
@@ -402,9 +403,7 @@ public class GbpNetconfTransaction {
                 }
             }
         }
-        alreadyRemoved.forEach(t -> {
-            iids.remove(t);
-        });
+        alreadyRemoved.forEach(t -> iids.remove(t));
         try {
             final CheckedFuture<Void, TransactionCommitFailedException> futureTask = rwTx.submit();
             futureTask.get();