[ONOS-3486] Add the annotation of port mac when monitor switch added.L3
flows need external port mac information.
Change-Id: I9afed351bd8d1641b8e9bef88718ec5c0ded8b5d
diff --git a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
index 4f81e92..38b599d 100644
--- a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
+++ b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java
@@ -113,6 +113,11 @@
public static final String PORT_NAME = "portName";
/**
+ * Annotation key for the port mac.
+ */
+ public static final String PORT_MAC = "portMac";
+
+ /**
* Annotation key for the router ID.
*/
public static final String ROUTER_ID = "routerId";
diff --git a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java
index a7e334f..4ceb425 100644
--- a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java
+++ b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java
@@ -516,7 +516,7 @@
PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN)
&& !port.getConfig().contains(OFPortConfig.PORT_DOWN);
- SparseAnnotations annotations = makePortNameAnnotation(port.getName());
+ SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString());
OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0);
OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType();
@@ -560,16 +560,19 @@
/**
* Creates an annotation for the port name if one is available.
*
- * @param port description of the port
+ * @param portName the port name
+ * @param portMac the port mac
* @return annotation containing the port name if one is found,
* null otherwise
*/
- private SparseAnnotations makePortNameAnnotation(String port) {
+ private SparseAnnotations makePortAnnotation(String portName, String portMac) {
SparseAnnotations annotations = null;
- String portName = Strings.emptyToNull(port);
+ String pName = Strings.emptyToNull(portName);
+ String pMac = Strings.emptyToNull(portMac);
if (portName != null) {
annotations = DefaultAnnotations.builder()
- .set(AnnotationKeys.PORT_NAME, portName).build();
+ .set(AnnotationKeys.PORT_NAME, pName)
+ .set(AnnotationKeys.PORT_MAC, pMac).build();
}
return annotations;
}
@@ -586,7 +589,7 @@
!port.getState().contains(OFPortState.LINK_DOWN) &&
!port.getConfig().contains(OFPortConfig.PORT_DOWN);
Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
- SparseAnnotations annotations = makePortNameAnnotation(port.getName());
+ SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString());
return new DefaultPortDescription(portNo, enabled, type,
portSpeed(port), annotations);
}
@@ -607,7 +610,7 @@
boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN)
&& !port.getConfig().contains(OFPortConfig.PORT_DOWN);
- SparseAnnotations annotations = makePortNameAnnotation(port.getName());
+ SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString());
if (port.getVersion() == OFVersion.OF_13
&& ptype == PortDescPropertyType.OPTICAL_TRANSPORT) {
@@ -649,7 +652,7 @@
// FIXME when Calient OF agent reports port status
boolean enabled = true;
- SparseAnnotations annotations = makePortNameAnnotation(port.getName());
+ SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString());
// S160 data sheet
// Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch
@@ -664,7 +667,7 @@
} else {
PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
- SparseAnnotations annotations = makePortNameAnnotation(port.getName());
+ SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString());
return new DefaultPortDescription(portNo, false, type,
portSpeed(port), annotations);
}