ONOS-7827 SIP for line ports (Photonic Media).

Change-Id: I4aa1e50ad4c0fbb9f281144b3a510a61395ac070
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipHandler.java
index 11f3d3d..f970417 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipHandler.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipHandler.java
@@ -31,6 +31,7 @@
 import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
 import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
 import static org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.layerprotocolname.LayerProtocolNameEnum.DSR;
+import static org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.layerprotocolname.LayerProtocolNameEnum.PHOTONIC_MEDIA;
 import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.tapicontext.DefaultServiceInterfacePoint;
 import org.onosproject.yang.model.ModelObjectId;
 import org.slf4j.Logger;
@@ -77,39 +78,81 @@
      * @return is this handler for SIP or not
      */
     public static boolean isSip(Port port) {
-        // RCAS Note: We may end up controlling more devices that do
-        // not have annotations or do not have the PORT_TYPE
-        // annotation. Let's accomodate other devices (e.g.
-        // OpenROADM) and be less strict. In short, if the
-        // annotation does not exist, simply return false.
-        //
-        // Note: for phase 1.5+ , we should also allow SIPs to
-        // be the transceiver LINE side, when we establish
-        // OpticalConnectivityIntent
-
+        /*
+         Note: We may end up controlling devices that do
+         not have annotations or do not have the PORT_TYPE
+         annotation (e.g. OpenROADM),
+         Instead of throwing, if the annotation does not
+         exist, simply return false.
+        */
         if (!port.annotations().keys().contains(PORT_TYPE)) {
             log.warn("No annotation of {} on port {}", PORT_TYPE, port);
             return false;
         }
+
+        // Port type will determine the SIP layer
         String portType = port.annotations().value(PORT_TYPE);
         OdtnDeviceDescriptionDiscovery.OdtnPortType odtnPortType
                 = OdtnDeviceDescriptionDiscovery.OdtnPortType.fromValue(portType);
-        return odtnPortType.value().equals(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value());
+
+        /*
+          Note: for phase 1.5+ , we allow SIPs to
+          be the transceiver LINE side, when we establish
+          OpticalConnectivityIntent (type PHOTONIC_MEDIA)
+        */
+        if (odtnPortType.value().equals(
+                OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value())) {
+            return true;
+        }
+        if (odtnPortType.value().equals(
+                OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value())) {
+            return true;
+        }
+        return false;
     }
 
+
     public TapiSipHandler setPort(Port port) {
         if (!isSip(port)) {
             throw new IllegalStateException("Not allowed to use this port as SIP.");
         }
         ConnectPoint cp = new ConnectPoint(port.element().id(), port.number());
-        return setConnectPoint(cp);
+        String portType = port.annotations().value(PORT_TYPE);
+        return setConnectPoint(cp, portType);
     }
 
+
+    /**
+     * Set Connect Point for this SIP.
+     * For backwards compatibility. Set SIP to client.
+     *
+     * @param cp the connect point
+     * @return TapiSipHandler instance
+     */
     public TapiSipHandler setConnectPoint(ConnectPoint cp) {
+        return setConnectPoint(cp,
+                OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value());
+    }
+
+    /**
+     * Set Connect Point for this SIP with a given port type.
+     *
+     * @param cp the connect point
+     * @param portType the port type
+     * @return TapiSipHandler instance
+     */
+    public TapiSipHandler setConnectPoint(ConnectPoint cp, String portType) {
         Map<String, String> kvs = new HashMap<>();
         kvs.put(ONOS_CP, cp.toString());
         addNameList(obj, kvs);
-        obj.layerProtocolName(LayerProtocolName.of(DSR));
+        if (portType.equals(
+                OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value())) {
+            obj.layerProtocolName(LayerProtocolName.of(DSR));
+        }
+        if (portType.equals(
+                OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value())) {
+            obj.layerProtocolName(LayerProtocolName.of(PHOTONIC_MEDIA));
+        }
         return this;
     }