OVSDB-457 Populate mac_in_use field for bridge ports 25/71025/4
authorVishal Thapar <vthapar@redhat.com>
Tue, 17 Apr 2018 10:41:50 +0000 (16:11 +0530)
committerSam Hague <shague@redhat.com>
Tue, 15 May 2018 22:37:37 +0000 (22:37 +0000)
1. Added yang for mac_in_use and mac fields.
2. Added method for updating Port's operational with mac_in_use
   and mac [if present].

Change-Id: Id0624b273a2e81910277f3041b2398e9fe8f0019
Signed-off-by: Vishal Thapar <vthapar@redhat.com>
southbound/southbound-api/src/main/yang/ovsdb.yang
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbPortUpdateCommand.java

index 6d3b7716e07c7a7f951dc67327ddf9fd5061089b..e37a1c72def8c03cac4b2abe2b17f6d205dc77e3 100755 (executable)
@@ -868,6 +868,17 @@ module ovsdb {
             config false;
         }
 
+        leaf mac {
+            description "Ethernet address to use for this interface. If unset, the default is used";
+            type yang:mac-address;
+        }
+
+        leaf mac-in-use {
+            description "The MAC address in use by this interface";
+            type yang:mac-address;
+            config false;
+        }
+
         leaf interface-type {
             description "The type of the OVSDB interface";
             type identityref {
index ac9ace2f2da27edd25d0d1171e2272bc787fb212..bc9be694577a54f8e7ac306910b1e507f9e2d483 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 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.l2.types.rev130827.VlanId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
@@ -277,6 +278,8 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand {
         ovsdbTerminationPointBuilder.setInterfaceType(
                 SouthboundMapper.createInterfaceType(type));
         updateIfIndex(interf, ovsdbTerminationPointBuilder);
+        updateMac(interf, ovsdbTerminationPointBuilder);
+        updateMacInUse(interf, ovsdbTerminationPointBuilder);
         updateOfPort(interf, ovsdbTerminationPointBuilder);
         updateOfPortRequest(interf, ovsdbTerminationPointBuilder);
         updateInterfaceExternalIds(interf, ovsdbTerminationPointBuilder);
@@ -435,6 +438,48 @@ public class OvsdbPortUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
+    private void updateMac(final Interface interf,
+                           final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointBuilder) {
+        Set<String> macSet = null;
+        try {
+            if (interf.getMacColumn() != null) {
+                macSet = interf.getMacColumn().getData();
+            }
+            if (macSet != null && !macSet.isEmpty()) {
+                /*
+                 * It is a set due to way JSON decoder converts [] objects. OVS
+                 * only supports ONE mac, so we're fine.
+                 */
+                for (String mac: macSet) {
+                    ovsdbTerminationPointBuilder.setMac(new MacAddress(mac));
+                }
+            }
+        } catch (SchemaVersionMismatchException e) {
+            schemaMismatchLog("mac", "Interface", e);
+        }
+    }
+
+    private void updateMacInUse(final Interface interf,
+                               final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointBuilder) {
+        Set<String> macInUseSet = null;
+        try {
+            if (interf.getMacInUseColumn() != null) {
+                macInUseSet = interf.getMacInUseColumn().getData();
+            }
+            if (macInUseSet != null && !macInUseSet.isEmpty()) {
+                /*
+                 * It is a set due to way JSON decoder converts [] objects. OVS
+                 * only supports ONE mac, so we're fine.
+                 */
+                for (String macInUse: macInUseSet) {
+                    ovsdbTerminationPointBuilder.setMacInUse(new MacAddress(macInUse));
+                }
+            }
+        } catch (SchemaVersionMismatchException e) {
+            schemaMismatchLog("mac_in_use", "Interface", e);
+        }
+    }
+
     private void updateOfPort(final Interface interf,
             final OvsdbTerminationPointAugmentationBuilder ovsdbTerminationPointBuilder) {