Amendments to displayNeutronPorts CLI + listed changes 31/41631/2
authorAbhinav Gupta <abhinav.gupta@ericsson.com>
Mon, 11 Jul 2016 06:58:09 +0000 (12:28 +0530)
committerAbhinav Gupta <abhinav.gupta@ericsson.com>
Mon, 11 Jul 2016 10:12:41 +0000 (15:42 +0530)
Following things are taken care of:

a. Displaying neutron ports without fixed IPs
b. Displaying neutron ports with multiple fixed IPs
c. Displaying neutron ports with IPv6 fixed IPs
d. Additional error handling to fail only one the failing ports, not
all, in case of any.

Also, done changes for the following:
i) neutron port addition/removal/updation in case of fixedIP not
present is handled.
ii) Add/remove of port to cache modified to be populated for all use cases

Change-Id: I9e2bfa6c7c0bccce6ce55eeb161ac47c94e93a09
Signed-off-by: Abhinav Gupta <abhinav.gupta@ericsson.com>
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronPortChangeListener.java
vpnservice/neutronvpn/neutronvpn-impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnManager.java

index cefcd5982d0bf7de573b9bb5f7da164d0777cbe8..9fdc29f5a3210745a6b691df217a990c87b9938b 100644 (file)
@@ -120,6 +120,8 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     input.getName(), network);
             return;
         }
+        NeutronvpnUtils.addToPortCache(input);
+
         /* check if router interface has been created */
         if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
             if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
@@ -128,8 +130,9 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                 return;
             }
         }
-        handleNeutronPortCreated(input);
-        NeutronvpnUtils.addToPortCache(input);
+        if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) {
+            handleNeutronPortCreated(input);
+        }
 
     }
 
@@ -145,6 +148,8 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                     input.getName(), network);
             return;
         }
+        NeutronvpnUtils.removeFromPortCache(input);
+
         if ((input.getDeviceOwner() != null) && (input.getDeviceId() != null)) {
             if (input.getDeviceOwner().equals(NeutronConstants.DEVICE_OWNER_ROUTER_INF)) {
                 handleRouterInterfaceRemoved(input);
@@ -152,8 +157,9 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                 return;
             }
         }
-        handleNeutronPortDeleted(input);
-        NeutronvpnUtils.removeFromPortCache(input);
+        if (input.getFixedIps() != null && !input.getFixedIps().isEmpty()) {
+            handleNeutronPortDeleted(input);
+        }
     }
 
     @Override
@@ -176,6 +182,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
         if (NeutronvpnUtils.isPortVifTypeUpdated(original, update)) {
             updateOfPortInterface(original, update);
         }
+        NeutronvpnUtils.addToPortCache(update);
 
         /* check if router interface has been updated */
         if ((update.getDeviceOwner() != null) && (update.getDeviceId() != null)) {
@@ -195,9 +202,7 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
                 }
             }
             handleNeutronPortUpdated(original, update);
-            NeutronvpnUtils.addToPortCache(update);
         }
-
         handlePortSecurityUpdated(original, update);
     }
 
@@ -292,6 +297,10 @@ public class NeutronPortChangeListener extends AbstractDataChangeListener<Port>
     }
 
     private void handleNeutronPortUpdated(Port portoriginal, Port portupdate) {
+        if (portoriginal.getFixedIps() == null || portoriginal.getFixedIps().isEmpty()) {
+            handleNeutronPortCreated(portupdate);
+            return;
+        }
         LOG.debug("Add port to subnet");
         // add port FixedIP to local Subnets DS
         Uuid vpnIdup = addPortToSubnets(portupdate);
index 215ca4b978439f7e234e30c333d9cfeb3d8bfdf0..2b0d5b605dee76b91dd6218245a56d5bb44e927a 100644 (file)
@@ -1557,18 +1557,38 @@ public class NeutronvpnManager implements NeutronvpnService, AutoCloseable, Even
 
     public List<String> showNeutronPortsCLI() {
         List<String> result = new ArrayList<>();
-        result.add(String.format(" %-34s  %-22s  %-22s  %-6s ", "PortName", "Mac Address", "IP Address",
-                "Prefix Length"));
-        result.add("---------------------------------------------------------------------------------------");
+        result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", "Port ID", "Mac Address", "Prefix Length", "IP " +
+                "Address"));
+        result.add("-------------------------------------------------------------------------------------------");
         InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
         try {
             Optional<Ports> ports = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, portidentifier);
             if (ports.isPresent() && ports.get().getPort() != null) {
                 for (Port port : ports.get().getPort()) {
-                    if (port.getFixedIps() != null && !port.getFixedIps().isEmpty()) {
-                        result.add(String.format(" %-34s  %-22s  %-22s  %-6s ", port.getUuid().getValue(), port
-                                .getMacAddress(), port.getFixedIps().get(0).getIpAddress().getIpv4Address().
-                                getValue(), NeutronvpnUtils.getIPPrefixFromPort(broker, port)));
+                    List<FixedIps> fixedIPs = port.getFixedIps();
+                    try {
+                        if (fixedIPs != null && !fixedIPs.isEmpty()) {
+                            List<String> ipList = new ArrayList<>();
+                            for (FixedIps fixedIp : fixedIPs) {
+                                IpAddress ipAddress = fixedIp.getIpAddress();
+                                if (ipAddress.getIpv4Address() != null) {
+                                    ipList.add(ipAddress.getIpv4Address().getValue());
+                                } else {
+                                    ipList.add((ipAddress.getIpv6Address().getValue()));
+                                }
+                            }
+                            result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", port.getUuid().getValue(), port
+                                    .getMacAddress().getValue(), NeutronvpnUtils.getIPPrefixFromPort(broker, port),
+                                    ipList.toString()));
+                        } else {
+                            result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", port.getUuid().getValue(), port
+                                    .getMacAddress().getValue(), "Not Assigned", "Not Assigned"));
+                        }
+                    } catch (Exception e) {
+                        logger.error("Failed to retrieve neutronPorts info for port {}: ", port.getUuid().getValue(),
+                                e);
+                        System.out.println("Failed to retrieve neutronPorts info for port: " + port.getUuid()
+                                .getValue() + ": " + e.getMessage());
                     }
                 }
             }