[ODTN] Add read/create/delete ConnectivityService RPC
- RPC: get service interface point
- RPC: get connectivity service list
- RPC: get connectivity service detail
- RPC: create connectivity service
- RPC: delete connectivity service
- Filter method of TAPI resolver for both Node / NEP
- Change condition for sip to odtn-port-type
- Use odtn-port-type in path-computation mock
- Create CEP at topology discovery
- Add sample path calculator
- Add connection-id based path selection
Change-Id: I2f08aacb3dd14b6b3c59a64a349e50abb495f70b
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNepRef.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNepRef.java
index 12df8cb..e5fcf2d 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNepRef.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNepRef.java
@@ -20,6 +20,9 @@
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.Node;
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.Topology;
+/**
+ * TAPI Nep reference class which has a factory method using DCS modelObject.
+ */
public final class DcsBasedTapiNepRef extends TapiNepRef {
private DcsBasedTapiNepRef(Topology topology, Node node, OwnedNodeEdgePoint nep) {
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNodeRef.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNodeRef.java
index cfc38e2..b6260a7 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNodeRef.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNodeRef.java
@@ -19,6 +19,9 @@
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.Node;
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.Topology;
+/**
+ * TAPI Node reference class which has a factory method using DCS modelObject.
+ */
public final class DcsBasedTapiNodeRef extends TapiNodeRef {
private DcsBasedTapiNodeRef(Topology topology, Node node) {
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepHandler.java
new file mode 100644
index 0000000..b49de0c
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepHandler.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.ceplist.DefaultConnectionEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectionendpoint.DefaultParentNodeEdgePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.node.DefaultOwnedNodeEdgePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.node.OwnedNodeEdgePointKeys;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultNode;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.NodeKeys;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys;
+import org.onosproject.yang.model.ModelObjectId;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
+
+/**
+ * Utility class to deal with TAPI CEP with DCS.
+ */
+public final class TapiCepHandler extends TapiObjectHandler<DefaultConnectionEndPoint> {
+
+ private Uuid topologyUuid;
+ private Uuid nodeUuid;
+ private Uuid nepUuid;
+
+ private TapiCepHandler() {
+ obj = new DefaultConnectionEndPoint();
+ setId();
+ }
+
+ public static TapiCepHandler create() {
+ return new TapiCepHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ checkNotNull(topologyUuid);
+ checkNotNull(nodeUuid);
+ checkNotNull(nodeUuid);
+
+ TopologyKeys topologyKey = new TopologyKeys();
+ topologyKey.uuid(topologyUuid);
+
+ NodeKeys nodeKey = new NodeKeys();
+ nodeKey.uuid(nodeUuid);
+
+ OwnedNodeEdgePointKeys nepKey = new OwnedNodeEdgePointKeys();
+ nepKey.uuid(nepUuid);
+
+ return ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .addChild(DefaultTopology.class, topologyKey)
+ .addChild(DefaultNode.class, nodeKey)
+ .addChild(DefaultOwnedNodeEdgePoint.class, nepKey)
+ .build();
+ }
+
+ public TapiCepHandler setTopologyUuid(Uuid topologyUuid) {
+ this.topologyUuid = topologyUuid;
+ return this;
+ }
+
+ public TapiCepHandler setNodeUuid(Uuid nodeUuid) {
+ this.nodeUuid = nodeUuid;
+ return this;
+ }
+
+ public TapiCepHandler setNepUuid(Uuid nepUuid) {
+ this.nepUuid = nepUuid;
+ return this;
+ }
+
+ public TapiCepHandler setParentNep() {
+ checkNotNull(topologyUuid);
+ checkNotNull(nodeUuid);
+ checkNotNull(nepUuid);
+
+ DefaultParentNodeEdgePoint parentNep = new DefaultParentNodeEdgePoint();
+ parentNep.topologyId(topologyUuid);
+ parentNep.nodeId(nodeUuid);
+ parentNep.ownedNodeEdgePointId(nepUuid);
+ obj.addToParentNodeEdgePoint(parentNep);
+
+ return this;
+ }
+
+ public TapiCepHandler setParentNep(TapiNepRef nepRef) {
+ topologyUuid = Uuid.fromString(nepRef.getTopologyId());
+ nodeUuid = Uuid.fromString(nepRef.getNodeId());
+ nepUuid = Uuid.fromString(nepRef.getNepId());
+
+ setParentNep();
+ return this;
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepPair.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepPair.java
new file mode 100644
index 0000000..f283bf3
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepPair.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * TAPI CepRef pair class for representation of endpoints of single connection.
+ */
+public final class TapiCepPair {
+
+ private TapiCepRef left;
+ private TapiCepRef right;
+
+ private TapiCepPair() {
+ }
+
+ public static TapiCepPair create(TapiCepRef left, TapiCepRef right) {
+ TapiCepPair self = new TapiCepPair();
+ self.left = left;
+ self.right = right;
+ return self;
+ }
+
+ public TapiCepRef left() {
+ return left;
+ }
+
+ public TapiCepRef right() {
+ return right;
+ }
+
+ public TapiNepPair getTapiNepPair() {
+ return TapiNepPair.create(left.getNepRef(), right.getNepRef());
+ }
+
+ public TapiCepPair invert() {
+ return TapiCepPair.create(right, left);
+ }
+
+ public boolean isSameNode() {
+ return left.getTopologyId().equals(right.getTopologyId()) && left.getNodeId().equals(right.getNodeId());
+ }
+
+ public Stream<TapiCepRef> stream() {
+ return Stream.of(left, right);
+ }
+
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("left", left)
+ .add("right", right)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof TapiCepPair)) {
+ return false;
+ }
+ TapiCepPair that = (TapiCepPair) o;
+ return Objects.equals(left, that.left) &&
+ Objects.equals(right, that.right);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(left, right);
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepRef.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepRef.java
new file mode 100644
index 0000000..15e3ecc
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepRef.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.Objects;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * TAPI Cep reference class.
+ * <p>
+ * TAPI reference class should be used in ODTN ServiceApplication
+ * in order to make independent ServiceApplication implementation from DCS.
+ */
+public final class TapiCepRef {
+
+ protected final Logger log = getLogger(getClass());
+
+ private final UUID topologyId;
+ private final UUID nodeId;
+ private final UUID nepId;
+ private final UUID cepId;
+
+ private TapiCepRef(String topologyId, String nodeId, String nepId, String cepId) {
+ this.topologyId = UUID.fromString(topologyId);
+ this.nodeId = UUID.fromString(nodeId);
+ this.nepId = UUID.fromString(nepId);
+ this.cepId = UUID.fromString(cepId);
+ }
+
+ public static TapiCepRef create(String topologyId, String nodeId, String nepId, String cepId) {
+ return new TapiCepRef(topologyId, nodeId, nepId, cepId);
+ }
+
+ public static TapiCepRef create(TapiNepRef nepRef, String cepId) {
+ return new TapiCepRef(nepRef.getTopologyId(), nepRef.getNodeId(), nepRef.getNepId(), cepId);
+ }
+
+ public String getTopologyId() {
+ return topologyId.toString();
+ }
+
+ public String getNodeId() {
+ return nodeId.toString();
+ }
+
+ public String getNepId() {
+ return nepId.toString();
+ }
+
+ public String getCepId() {
+ return cepId.toString();
+ }
+
+ public TapiNepRef getNepRef() {
+ return new TapiNepRef(topologyId.toString(), nodeId.toString(), nepId.toString());
+ }
+
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("topologyId", topologyId)
+ .add("nodeId", nodeId)
+ .add("nepId", nepId)
+ .add("cepId", cepId)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof TapiCepRef)) {
+ return false;
+ }
+ TapiCepRef that = (TapiCepRef) o;
+ return Objects.equals(topologyId, that.topologyId) &&
+ Objects.equals(nodeId, that.nodeId) &&
+ Objects.equals(nepId, that.nepId) &&
+ Objects.equals(cepId, that.cepId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(topologyId, nodeId, nepId, cepId);
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepRefHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepRefHandler.java
new file mode 100644
index 0000000..38acd75
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCepRefHandler.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.ceplist.ConnectionEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.DefaultConnectionEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectionendpoint.ParentNodeEdgePoint;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility class to deal with TAPI CepRef with DCS.
+ */
+public final class TapiCepRefHandler extends TapiObjectHandler<DefaultConnectionEndPoint> {
+
+ private TapiCepRefHandler() {
+ obj = new DefaultConnectionEndPoint();
+ }
+
+ public static TapiCepRefHandler create() {
+ return new TapiCepRefHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return (Uuid) obj.connectionEndPointId();
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {}
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return null;
+ }
+
+ public TapiCepRefHandler setCep(TapiCepRef cepRef) {
+ obj.topologyId(cepRef.getTopologyId());
+ obj.nodeId(cepRef.getNodeId());
+ obj.ownedNodeEdgePointId(cepRef.getNepId());
+ obj.connectionEndPointId(cepRef.getCepId());
+ return this;
+ }
+
+ public TapiCepRefHandler setCep(ConnectionEndPoint cep) {
+ obj.connectionEndPointId(cep.uuid());
+ ParentNodeEdgePoint parentNep = cep.parentNodeEdgePoint().get(0);
+ obj.topologyId(parentNep.topologyId());
+ obj.nodeId(parentNep.nodeId());
+ obj.ownedNodeEdgePointId(parentNep.ownedNodeEdgePointId());
+ return this;
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnection.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnection.java
new file mode 100644
index 0000000..f81ec1a
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnection.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+public final class TapiConnection {
+
+ private TapiCepPair ceps;
+ private List<TapiConnection> lowerConnections = new ArrayList<>();
+
+ private TapiConnection(TapiCepPair ceps) {
+ this.ceps = ceps;
+ }
+
+ public static TapiConnection create(TapiCepPair ceps) {
+ return new TapiConnection(ceps);
+ }
+
+ public static TapiConnection create(TapiCepRef left, TapiCepRef right) {
+ TapiCepPair cepPair = TapiCepPair.create(left, right);
+ return new TapiConnection(cepPair);
+ }
+
+ public TapiCepPair getCeps() {
+ return ceps;
+ }
+
+ public List<TapiConnection> getLowerConnections() {
+ return lowerConnections;
+ }
+
+ public TapiConnection addLowerConnection(TapiConnection lowerConnection) {
+ this.lowerConnections.add(lowerConnection);
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("ceps", ceps)
+ .add("lowerConnection", lowerConnections)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof TapiConnection)) {
+ return false;
+ }
+ TapiConnection that = (TapiConnection) o;
+ return Objects.equals(ceps, that.ceps) &&
+ Objects.equals(lowerConnections, that.lowerConnections);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(ceps, lowerConnections);
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectionHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectionHandler.java
new file mode 100644
index 0000000..b3d6f3e
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectionHandler.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.ConnectionEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.DefaultConnectionEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.DefaultLowerConnection;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.DefaultRoute;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.LowerConnection;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectionKeys;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnection;
+import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
+
+/**
+ * Utility class to deal with TAPI Connection with DCS.
+ */
+public final class TapiConnectionHandler extends TapiObjectHandler<DefaultConnection> {
+
+ private TapiConnectionHandler() {
+ obj = new DefaultConnection();
+ setId();
+ }
+
+ public static TapiConnectionHandler create() {
+ return new TapiConnectionHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return ModelObjectId.builder().addChild(DefaultContext.class).build();
+ }
+
+ @Override
+ public ModelObjectData getChildModelObjectData() {
+
+ ConnectionKeys key = new ConnectionKeys();
+ key.uuid(getId());
+
+ DefaultConnectionEndPoint mObj = new DefaultConnectionEndPoint();
+
+ ModelObjectId mId = ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .addChild(DefaultConnection.class, key)
+ .build();
+
+ return DefaultModelObjectData.builder()
+ .addModelObject(mObj)
+ .identifier(mId)
+ .build();
+ }
+
+ public TapiConnectionHandler addCep(ConnectionEndPoint cep) {
+ obj.addToConnectionEndPoint(cep);
+ return this;
+ }
+
+ public TapiConnectionHandler addLowerConnection(DefaultConnection connection) {
+ DefaultLowerConnection lowerConnection = new DefaultLowerConnection();
+ lowerConnection.connectionId(connection.uuid());
+ obj.addToLowerConnection(lowerConnection);
+ return this;
+ }
+
+ public TapiConnectionHandler addRoute(DefaultRoute route) {
+ obj.addToRoute(route);
+ return this;
+ }
+
+ public List<TapiConnectionHandler> getLowerConnections() {
+
+ try {
+ return obj.lowerConnection().stream()
+ .map(LowerConnection::connectionId)
+ .map(id -> {
+ TapiConnectionHandler handler = new TapiConnectionHandler();
+ handler.setId(Uuid.fromString(id.toString()));
+ return handler;
+ }).collect(Collectors.toList());
+ } catch (NullPointerException e) {
+ return Collections.emptyList();
+ }
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java
new file mode 100644
index 0000000..89ac48e
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiConnectivityServiceHandler.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectivityServiceKeys;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivityservice.DefaultConnection;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivityservice.EndPoint;
+import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
+
+/**
+ * Utility class to deal with TAPI ConnectivityService with DCS.
+ */
+public final class TapiConnectivityServiceHandler extends TapiObjectHandler<DefaultConnectivityService> {
+
+ private TapiConnectivityServiceHandler() {
+ obj = new DefaultConnectivityService();
+ setId();
+ }
+
+ public static TapiConnectivityServiceHandler create() {
+ return new TapiConnectivityServiceHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return ModelObjectId.builder().addChild(DefaultContext.class).build();
+ }
+
+ @Override
+ public ModelObjectData getChildModelObjectData() {
+
+ ConnectivityServiceKeys key = new ConnectivityServiceKeys();
+ key.uuid(getId());
+
+ DefaultConnection mObj = new DefaultConnection();
+
+ ModelObjectId mId = ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .addChild(DefaultConnectivityService.class, key)
+ .build();
+
+ return DefaultModelObjectData.builder()
+ .addModelObject(mObj)
+ .identifier(mId)
+ .build();
+ }
+
+ public TapiConnectivityServiceHandler addSep(EndPoint sep) {
+ obj.addToEndPoint(sep);
+ return this;
+ }
+
+ public TapiConnectivityServiceHandler addConnection(Uuid connectionUuid) {
+ DefaultConnection connection = new DefaultConnection();
+ connection.connectionId(connectionUuid.toString());
+ obj.addToConnection(connection);
+ return this;
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextBuilder.java
deleted file mode 100644
index 720d436..0000000
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.odtn.utils.tapi;
-
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
-import org.onosproject.yang.model.ModelObjectId;
-
-/**
- * Utility builder class for TAPI context creation with DCS.
- */
-public final class TapiContextBuilder extends TapiInstanceBuilder {
-
- private DefaultContext context;
-
- private TapiContextBuilder(DefaultContext context) {
- this.context = context;
- }
-
- public static TapiContextBuilder builder(DefaultContext context) {
- return new TapiContextBuilder(context);
- }
-
- @Override
- public ModelObjectId getModelObjectId() {
- return ModelObjectId.builder().build();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public DefaultContext getModelObject() {
- return context;
- }
-
- @Override
- public Uuid getUuid() {
- return null;
- }
-}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextHandler.java
new file mode 100644
index 0000000..ff8e24d
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextHandler.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.context.DefaultAugmentedTapiCommonContext;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
+import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility class to deal with TAPI Context with DCS.
+ */
+public final class TapiContextHandler extends TapiObjectHandler<DefaultContext> {
+
+ private TapiContextHandler() {
+ obj = new DefaultContext();
+ }
+
+ public static TapiContextHandler create() {
+ return new TapiContextHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return null;
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return ModelObjectId.builder().build();
+ }
+
+ @Override
+ public ModelObjectData getChildModelObjectData() {
+
+ ModelObjectId mId = ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .build();
+
+ DefaultTopology mObj = new DefaultTopology();
+
+ return DefaultModelObjectData.builder()
+ .addModelObject(mObj)
+ .identifier(mId)
+ .build();
+ }
+
+ public List<TapiConnectivityServiceHandler> getConnectivityServices() {
+
+ DefaultAugmentedTapiCommonContext augmentedContext = obj.augmentation(DefaultAugmentedTapiCommonContext.class);
+ try {
+ return augmentedContext.connectivityService().stream()
+ .map(connectivityService -> {
+ TapiConnectivityServiceHandler handler = TapiConnectivityServiceHandler.create();
+ handler.setModelObject((DefaultConnectivityService) connectivityService);
+ return handler;
+ }).collect(Collectors.toList());
+ } catch (NullPointerException e) {
+ return Collections.emptyList();
+ }
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCreateConnectivityInputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCreateConnectivityInputHandler.java
new file mode 100644
index 0000000..1a182b8
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCreateConnectivityInputHandler.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.createconnectivityservice.CreateConnectivityServiceInput;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.createconnectivityservice.DefaultCreateConnectivityServiceInput;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.createconnectivityservice.createconnectivityserviceinput.EndPoint;
+
+/**
+ * Utility class to deal with TAPI RPC input with DCS.
+ */
+public final class TapiCreateConnectivityInputHandler
+ extends TapiRpcInputHandler<DefaultCreateConnectivityServiceInput> {
+
+ public List<EndPoint> getEndPoints() {
+ List<EndPoint> eps = CreateConnectivityServiceInput.class.cast(obj).endPoint();
+ if (eps == null) {
+ return Collections.emptyList();
+ }
+ return eps;
+ }
+
+ public List<String> getSips() {
+ return getEndPoints().stream()
+ .map(ep -> ep.serviceInterfacePoint().serviceInterfacePointId().toString())
+ .collect(Collectors.toList());
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCreateConnectivityOutputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCreateConnectivityOutputHandler.java
new file mode 100644
index 0000000..f503072
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiCreateConnectivityOutputHandler.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.createconnectivityservice.DefaultCreateConnectivityServiceOutput;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.createconnectivityservice.createconnectivityserviceoutput.DefaultService;
+
+/**
+ * Utility class to deal with TAPI RPC output with DCS.
+ */
+public final class TapiCreateConnectivityOutputHandler
+ extends TapiRpcOutputHandler<DefaultCreateConnectivityServiceOutput> {
+
+ private TapiCreateConnectivityOutputHandler() {
+ obj = new DefaultCreateConnectivityServiceOutput();
+ }
+
+ public static TapiCreateConnectivityOutputHandler create() {
+ return new TapiCreateConnectivityOutputHandler();
+ }
+
+ public TapiCreateConnectivityOutputHandler addService(ConnectivityService res) {
+ DefaultService rpcOutputService = new DefaultService();
+ rpcOutputService.uuid(res.uuid());
+ res.connection().forEach(rpcOutputService::addToConnection);
+ res.endPoint().forEach(rpcOutputService::addToEndPoint);
+ obj.service(rpcOutputService);
+ return this;
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiDeleteConnectivityInputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiDeleteConnectivityInputHandler.java
new file mode 100644
index 0000000..75d854e
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiDeleteConnectivityInputHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.UUID;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.deleteconnectivityservice.DefaultDeleteConnectivityServiceInput;
+
+/**
+ * Utility class to deal with TAPI RPC input with DCS.
+ */
+public final class TapiDeleteConnectivityInputHandler
+ extends TapiRpcInputHandler<DefaultDeleteConnectivityServiceInput> {
+
+ public Uuid getId() {
+ String idOrName = obj.serviceIdOrName();
+ UUID uuid = UUID.fromString(idOrName);
+ return Uuid.fromString(uuid.toString());
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiDeleteConnectivityOutputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiDeleteConnectivityOutputHandler.java
new file mode 100644
index 0000000..34186a4
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiDeleteConnectivityOutputHandler.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.deleteconnectivityservice.DefaultDeleteConnectivityServiceOutput;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.deleteconnectivityservice.deleteconnectivityserviceoutput.DefaultService;
+
+/**
+ * Utility class to deal with TAPI RPC output with DCS.
+ */
+public final class TapiDeleteConnectivityOutputHandler
+ extends TapiRpcOutputHandler<DefaultDeleteConnectivityServiceOutput> {
+
+ private TapiDeleteConnectivityOutputHandler() {
+ obj = new DefaultDeleteConnectivityServiceOutput();
+ }
+
+ public static TapiDeleteConnectivityOutputHandler create() {
+ return new TapiDeleteConnectivityOutputHandler();
+ }
+
+ public TapiDeleteConnectivityOutputHandler addService(ConnectivityService res) {
+ log.info("Output service: {}", res);
+ DefaultService rpcOutputService = new DefaultService();
+ rpcOutputService.uuid(res.uuid());
+ obj.service(rpcOutputService);
+ return this;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityDetailsInputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityDetailsInputHandler.java
new file mode 100644
index 0000000..ca01812
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityDetailsInputHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.UUID;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.getconnectivityservicedetails.DefaultGetConnectivityServiceDetailsInput;
+
+/**
+ * Utility class to deal with TAPI RPC input with DCS.
+ */
+public final class TapiGetConnectivityDetailsInputHandler
+ extends TapiRpcInputHandler<DefaultGetConnectivityServiceDetailsInput> {
+
+ public Uuid getId() {
+ String idOrName = obj.serviceIdOrName();
+ UUID uuid = UUID.fromString(idOrName);
+ return Uuid.fromString(uuid.toString());
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityDetailsOutputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityDetailsOutputHandler.java
new file mode 100644
index 0000000..1d7b02d
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityDetailsOutputHandler.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.getconnectivityservicedetails.DefaultGetConnectivityServiceDetailsOutput;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.getconnectivityservicedetails.getconnectivityservicedetailsoutput.DefaultService;
+
+/**
+ * Utility class to deal with TAPI RPC output with DCS.
+ */
+public final class TapiGetConnectivityDetailsOutputHandler
+ extends TapiRpcOutputHandler<DefaultGetConnectivityServiceDetailsOutput> {
+
+ private TapiGetConnectivityDetailsOutputHandler() {
+ obj = new DefaultGetConnectivityServiceDetailsOutput();
+ }
+
+ public static TapiGetConnectivityDetailsOutputHandler create() {
+ return new TapiGetConnectivityDetailsOutputHandler();
+ }
+
+ public TapiGetConnectivityDetailsOutputHandler addService(ConnectivityService res) {
+ DefaultService rpcOutputService = new DefaultService();
+ rpcOutputService.uuid(res.uuid());
+ res.connection().forEach(rpcOutputService::addToConnection);
+ res.endPoint().forEach(rpcOutputService::addToEndPoint);
+ obj.service(rpcOutputService);
+ return this;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityListOutputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityListOutputHandler.java
new file mode 100644
index 0000000..99bc678
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetConnectivityListOutputHandler.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.getconnectivityservicelist.DefaultGetConnectivityServiceListOutput;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.getconnectivityservicelist.getconnectivityservicelistoutput.DefaultService;
+
+/**
+ * Utility class to deal with TAPI RPC output with DCS.
+ */
+public final class TapiGetConnectivityListOutputHandler
+ extends TapiRpcOutputHandler<DefaultGetConnectivityServiceListOutput> {
+
+ private TapiGetConnectivityListOutputHandler() {
+ obj = new DefaultGetConnectivityServiceListOutput();
+ }
+
+ public static TapiGetConnectivityListOutputHandler create() {
+ return new TapiGetConnectivityListOutputHandler();
+ }
+
+ public TapiGetConnectivityListOutputHandler addService(ConnectivityService res) {
+ DefaultService rpcOutputService = new DefaultService();
+ rpcOutputService.uuid(res.uuid());
+ res.connection().forEach(rpcOutputService::addToConnection);
+ res.endPoint().forEach(rpcOutputService::addToEndPoint);
+ obj.addToService(rpcOutputService);
+ return this;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetSipListOutputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetSipListOutputHandler.java
new file mode 100644
index 0000000..95143d6
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGetSipListOutputHandler.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.getserviceinterfacepointlist.DefaultGetServiceInterfacePointListOutput;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.getserviceinterfacepointlist.getserviceinterfacepointlistoutput.DefaultSip;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.getserviceinterfacepointlist.getserviceinterfacepointlistoutput.Sip;
+
+/**
+ * Utility class to deal with TAPI RPC output with DCS.
+ */
+public final class TapiGetSipListOutputHandler
+ extends TapiRpcOutputHandler<DefaultGetServiceInterfacePointListOutput> {
+
+ private TapiGetSipListOutputHandler() {
+ obj = new DefaultGetServiceInterfacePointListOutput();
+ }
+
+ public static TapiGetSipListOutputHandler create() {
+ return new TapiGetSipListOutputHandler();
+ }
+
+ public TapiGetSipListOutputHandler addSip(Uuid sipId) {
+ Sip sip = new DefaultSip();
+ sip.uuid(sipId);
+ obj.addToSip(sip);
+ return this;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGlobalClassUtil.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGlobalClassUtil.java
index 2af7fed..200c623 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGlobalClassUtil.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGlobalClassUtil.java
@@ -25,35 +25,35 @@
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.UUID;
import org.slf4j.Logger;
+
import static org.slf4j.LoggerFactory.getLogger;
/**
* Utility methods dealing with TAPI modelObject which includes global class grouping.
- *
+ * <p>
* <p> tapi-common@2018-03-07.yang
* grouping global-class {
- * leaf uuid {
- * type uuid;
- * }
- * list name {
- * key 'value-name';
- * uses name-and-value;
- * }
+ * leaf uuid {
+ * type uuid;
* }
- *
+ * list name {
+ * key 'value-name';
+ * uses name-and-value;
+ * }
+ * }
+ * <p>
* grouping name-and-value {
- * leaf value-name {
- * type string;
- * description "The name of the value. The value need not have a name.";
- * }
- * leaf value {
- * type string;
- * description "The value";
- * }
- * description "A scoped name-value pair";
+ * leaf value-name {
+ * type string;
+ * description "The name of the value. The value need not have a name.";
+ * }
+ * leaf value {
+ * type string;
+ * description "The value";
+ * }
+ * description "A scoped name-value pair";
* }
* </p>
*/
@@ -65,14 +65,13 @@
}
/**
- * Generate and set Uuid for the ModelObject.
- * @param obj ModelObject
- * @param <T> type of ModelObject
- * @return generated uuid
+ * Set uuid for the ModelObject.
+ *
+ * @param obj ModelObject
+ * @param uuid Uuid
+ * @param <T> Type of ModelObject
*/
- public static <T extends ModelObject> Uuid setUuid(T obj) {
- Uuid uuid = Uuid.of(UUID.randomUUID().toString());
-
+ public static <T extends ModelObject> void setUuid(T obj, Uuid uuid) {
@SuppressWarnings("unchecked")
Class<T> cls = (Class<T>) obj.getClass();
try {
@@ -81,15 +80,35 @@
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
log.error("Exception thrown", e);
}
+ }
+
+ /**
+ * Get uuid for the ModelObject.
+ *
+ * @param obj ModelObject
+ * @param <T> Type of ModelObject
+ * @return Uuid
+ */
+ public static <T extends ModelObject> Uuid getUuid(T obj) {
+ Uuid uuid = null;
+ @SuppressWarnings("unchecked")
+ Class<T> cls = (Class<T>) obj.getClass();
+ try {
+ Method method = cls.getMethod("uuid");
+ uuid = (Uuid) method.invoke(obj);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ log.error("Exception thrown", e);
+ }
return uuid;
}
/**
* Add key-value to the ModelObject as "name-and-value" list.
+ *
* @param obj ModelObject
- * @param kvs key-value map
- * @param <T> type of ModelObject
+ * @param kvs Key-value map
+ * @param <T> Type of ModelObject
*/
public static <T extends ModelObject> void addNameList(T obj, Map<String, String> kvs) {
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiInstanceBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiInstanceBuilder.java
deleted file mode 100644
index dc4fd10..0000000
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiInstanceBuilder.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.odtn.utils.tapi;
-
-import java.util.List;
-import org.onlab.util.XmlString;
-import org.onosproject.config.DynamicConfigService;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
-import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.DefaultModelObjectData;
-import org.onosproject.yang.model.ModelConverter;
-import org.onosproject.yang.model.ModelObject;
-import org.onosproject.yang.model.ModelObjectData;
-import org.onosproject.yang.model.ModelObjectId;
-import org.onosproject.yang.model.ResourceData;
-
-import static org.onlab.osgi.DefaultServiceDirectory.getService;
-import static org.onosproject.odtn.utils.YangToolUtil.toCharSequence;
-import static org.onosproject.odtn.utils.YangToolUtil.toCompositeData;
-import static org.onosproject.odtn.utils.YangToolUtil.toXmlCompositeStream;
-
-import org.onosproject.yang.model.ResourceId;
-import org.slf4j.Logger;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Utility builder class for TAPI modelobject creation with DCS.
- */
-public abstract class TapiInstanceBuilder {
-
- public static final String ONOS_CP = "onos-cp";
-
- public static final String DEVICE_ID = "device-id";
-
- public static final String ODTN_PORT_TYPE = "odtn-port-type";
-
- private final Logger log = getLogger(getClass());
-
- private ModelConverter modelConverter;
- private DynamicConfigService dcs;
-
- /**
- * Generate DCS modelObjectData.
- *
- * @return ModelObjectId of build target
- */
- public abstract ModelObjectId getModelObjectId();
-
- /**
- * Get modelObject instance.
- *
- * @param <T> build target class
- * @return ModelObject of build target
- */
- public abstract <T extends ModelObject> T getModelObject();
-
- /**
- * Get modelObject uuid.
- *
- * @return Uuid of build target
- */
- public abstract Uuid getUuid();
-
- /**
- * Get modelObjectData instance.
- *
- * @return ModelObjectData of build target
- */
- public ModelObjectData getModelObjectData() {
- ModelObject obj = getModelObject();
- ModelObjectId objId = getModelObjectId();
-
- return DefaultModelObjectData.builder()
- .addModelObject(obj)
- .identifier(objId)
- .build();
- }
-
- /**
- * Add built modelObject to Dcs store.
- */
- public void build() {
- dcs = getService(DynamicConfigService.class);
- modelConverter = getService(ModelConverter.class);
- addModelObjectDataToDcs(getModelObjectData());
- }
-
- private void addModelObjectDataToDcs(ModelObjectData input) {
-
- ResourceData rnode = modelConverter.createDataNode(input);
-
- // for debug
- CharSequence strNode = toCharSequence(toXmlCompositeStream(toCompositeData(rnode)));
- log.info("XML:\n{}", XmlString.prettifyXml(strNode));
-
- addResourceDataToDcs(rnode);
- }
-
- private void addResourceDataToDcs(ResourceData input) {
- addResourceDataToDcs(input, input.resourceId());
- }
-
- private void addResourceDataToDcs(ResourceData input, ResourceId rid) {
- if (input == null || input.dataNodes() == null) {
- return;
- }
- List<DataNode> dataNodes = input.dataNodes();
- for (DataNode node : dataNodes) {
- dcs.createNode(rid, node);
- }
- }
-
-}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkHandler.java
similarity index 71%
rename from apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkBuilder.java
rename to apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkHandler.java
index 31107ae..2af1cb1 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkBuilder.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkHandler.java
@@ -24,40 +24,39 @@
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys;
import org.onosproject.yang.model.ModelObjectId;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
/**
- * Utility builder class for TAPI link creation with DCS.
+ * Utility class to deal with TAPI Link with DCS.
*/
-public final class TapiLinkBuilder extends TapiInstanceBuilder {
+public final class TapiLinkHandler extends TapiObjectHandler<DefaultLink> {
private Uuid topologyUuid;
- private DefaultLink link = new DefaultLink();
- private TapiLinkBuilder() {
- setUuid(link);
+ private TapiLinkHandler() {
+ obj = new DefaultLink();
+ setId();
}
- public static TapiLinkBuilder builder() {
- return new TapiLinkBuilder();
- }
-
- public TapiLinkBuilder setTopologyUuid(Uuid topologyUuid) {
- this.topologyUuid = topologyUuid;
- return this;
- }
-
- public TapiLinkBuilder addNep(TapiNepRef nepRef) {
- DefaultNodeEdgePoint nep = new DefaultNodeEdgePoint();
- nep.topologyId(nepRef.getTopologyId());
- nep.nodeId(nepRef.getNodeId());
- nep.ownedNodeEdgePointId(nepRef.getNepId());
- link.addToNodeEdgePoint(nep);
- return this;
+ public static TapiLinkHandler create() {
+ return new TapiLinkHandler();
}
@Override
- public ModelObjectId getModelObjectId() {
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ checkNotNull(topologyUuid);
TopologyKeys topologyKey = new TopologyKeys();
topologyKey.uuid(topologyUuid);
@@ -67,15 +66,18 @@
.build();
}
- @Override
- @SuppressWarnings("unchecked")
- public DefaultLink getModelObject() {
- return link;
+ public TapiLinkHandler setTopologyUuid(Uuid topologyUuid) {
+ this.topologyUuid = topologyUuid;
+ return this;
}
- @Override
- public Uuid getUuid() {
- return link.uuid();
+ public TapiLinkHandler addNep(TapiNepRef nepRef) {
+ DefaultNodeEdgePoint nep = new DefaultNodeEdgePoint();
+ nep.topologyId(nepRef.getTopologyId());
+ nep.nodeId(nepRef.getNodeId());
+ nep.ownedNodeEdgePointId(nepRef.getNepId());
+ obj.addToNodeEdgePoint(nep);
+ return this;
}
}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLocalClassUtil.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLocalClassUtil.java
new file mode 100644
index 0000000..f593d20
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLocalClassUtil.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.globalclass.DefaultName;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.globalclass.Name;
+import org.onosproject.yang.model.ModelObject;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Utility methods dealing with TAPI modelObject which includes local class grouping.
+ * <p>
+ * <p> tapi-common@2018-03-07.yang
+ * grouping local-class {
+ * leaf local-id {
+ * type string;
+ * }
+ * list name {
+ * key 'value-name';
+ * uses name-and-value;
+ * }
+ * }
+ * <p>
+ * grouping name-and-value {
+ * leaf value-name {
+ * type string;
+ * description "The name of the value. The value need not have a name.";
+ * }
+ * leaf value {
+ * type string;
+ * description "The value";
+ * }
+ * description "A scoped name-value pair";
+ * }
+ * </p>
+ */
+public final class TapiLocalClassUtil {
+
+ private static final Logger log = getLogger(TapiLocalClassUtil.class);
+
+ private TapiLocalClassUtil() {
+ }
+
+ /**
+ * Set local-id for the ModelObject.
+ *
+ * @param obj ModelObject
+ * @param localId LocalId
+ * @param <T> Type of ModelObject
+ */
+ public static <T extends ModelObject> void setLocalId(T obj, String localId) {
+ @SuppressWarnings("unchecked")
+ Class<T> cls = (Class<T>) obj.getClass();
+ try {
+ Method method = cls.getMethod("localId", String.class);
+ method.invoke(obj, localId);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ log.error("Exception thrown", e);
+ }
+ }
+
+ /**
+ * Get local-id for the ModelObject.
+ *
+ * @param obj ModelObject
+ * @param <T> Type of ModelObject
+ * @return Local-id
+ */
+ public static <T extends ModelObject> String getLocalId(T obj) {
+ String localId = null;
+ @SuppressWarnings("unchecked")
+ Class<T> cls = (Class<T>) obj.getClass();
+ try {
+ Method method = cls.getMethod("localId");
+ localId = (String) method.invoke(obj);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ log.error("Exception thrown", e);
+ }
+
+ return localId;
+ }
+
+ /**
+ * Add key-value to the ModelObject as "name-and-value" list.
+ *
+ * @param obj ModelObject
+ * @param kvs Key-value map
+ * @param <T> Type of ModelObject
+ */
+ public static <T extends ModelObject> void addNameList(T obj, Map<String, String> kvs) {
+
+ @SuppressWarnings("unchecked")
+ Class<T> cls = (Class<T>) obj.getClass();
+ try {
+ Method method = cls.getMethod("addToName", Name.class);
+
+ for (Entry<String, String> kv : kvs.entrySet()) {
+ DefaultName prop = new DefaultName();
+ prop.valueName(kv.getKey());
+ prop.value(kv.getValue());
+ method.invoke(obj, prop);
+ }
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ log.error("Exception thrown", e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepBuilder.java
deleted file mode 100644
index 1148511..0000000
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepBuilder.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.odtn.utils.tapi;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.onosproject.net.ConnectPoint;
-
-import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
-import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
-
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
-import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.node.DefaultOwnedNodeEdgePoint;
-import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.nodeedgepoint.DefaultMappedServiceInterfacePoint;
-import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultNode;
-import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.NodeKeys;
-import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
-import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys;
-import org.onosproject.yang.model.ModelObjectId;
-
-/**
- * Utility builder class for TAPI nep creation with DCS.
- */
-public final class TapiNepBuilder extends TapiInstanceBuilder {
-
- private Uuid topologyUuid;
- private Uuid nodeUuid;
- private DefaultOwnedNodeEdgePoint nep = new DefaultOwnedNodeEdgePoint();
- private ConnectPoint cp;
- private Map<String, String> kvs = new HashMap<>();
-
- private TapiNepBuilder() {
- setUuid(nep);
- }
-
- public static TapiNepBuilder builder() {
- return new TapiNepBuilder();
- }
-
- public TapiNepBuilder setTopologyUuid(Uuid topologyUuid) {
- this.topologyUuid = topologyUuid;
- return this;
- }
-
- public TapiNepBuilder setNodeUuid(Uuid nodeUuid) {
- this.nodeUuid = nodeUuid;
- return this;
- }
-
- public TapiNepBuilder setConnectPoint(ConnectPoint cp) {
- kvs.put(ONOS_CP, cp.toString());
- addNameList(nep, kvs);
- return this;
- }
-
- public TapiNepBuilder addSip(Uuid sipUuid) {
- DefaultMappedServiceInterfacePoint mappedSip = new DefaultMappedServiceInterfacePoint();
- mappedSip.serviceInterfacePointId(sipUuid);
- nep.addToMappedServiceInterfacePoint(mappedSip);
- return this;
- }
-
- public ConnectPoint getConnectPoint() {
- return cp;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public DefaultOwnedNodeEdgePoint getModelObject() {
- return nep;
- }
-
- @Override
- public Uuid getUuid() {
- return nep.uuid();
- }
-
- @Override
- public ModelObjectId getModelObjectId() {
- TopologyKeys topologyKey = new TopologyKeys();
- topologyKey.uuid(topologyUuid);
-
- NodeKeys nodeKey = new NodeKeys();
- nodeKey.uuid(nodeUuid);
-
- return ModelObjectId.builder()
- .addChild(DefaultContext.class)
- .addChild(DefaultTopology.class, topologyKey)
- .addChild(DefaultNode.class, nodeKey)
- .build();
- }
-
-}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepHandler.java
new file mode 100644
index 0000000..2934b3e
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepHandler.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.onosproject.net.ConnectPoint;
+
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
+
+import org.onosproject.net.Port;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.ceplist.DefaultConnectionEndPoint;
+
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.context.topology.node.ownednodeedgepoint.DefaultAugmentedTapiTopologyOwnedNodeEdgePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.node.DefaultOwnedNodeEdgePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.nodeedgepoint.DefaultMappedServiceInterfacePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultNode;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.NodeKeys;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility class to deal with TAPI NEP with DCS.
+ */
+public final class TapiNepHandler extends TapiObjectHandler<DefaultOwnedNodeEdgePoint> {
+
+ private Uuid topologyUuid;
+ private Uuid nodeUuid;
+
+ private ConnectPoint cp;
+ private Map<String, String> kvs = new HashMap<>();
+
+ private TapiNepHandler() {
+ obj = new DefaultOwnedNodeEdgePoint();
+ setId();
+ }
+
+ public static TapiNepHandler create() {
+ return new TapiNepHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ TopologyKeys topologyKey = new TopologyKeys();
+ topologyKey.uuid(topologyUuid);
+
+ NodeKeys nodeKey = new NodeKeys();
+ nodeKey.uuid(nodeUuid);
+
+ return ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .addChild(DefaultTopology.class, topologyKey)
+ .addChild(DefaultNode.class, nodeKey)
+ .build();
+ }
+
+ public TapiNepHandler setTopologyUuid(Uuid topologyUuid) {
+ this.topologyUuid = topologyUuid;
+ return this;
+ }
+
+ public TapiNepHandler setNodeUuid(Uuid nodeUuid) {
+ this.nodeUuid = nodeUuid;
+ return this;
+ }
+
+ public TapiNepHandler setPort(Port port) {
+ ConnectPoint cp = new ConnectPoint(port.element().id(), port.number());
+ kvs.put(ODTN_PORT_TYPE, port.annotations().value(ODTN_PORT_TYPE));
+ kvs.put(CONNECTION_ID, port.annotations().value(CONNECTION_ID));
+ addNameList(obj, kvs);
+ return setConnectPoint(cp);
+ }
+
+ public TapiNepHandler setConnectPoint(ConnectPoint cp) {
+ kvs.put(ONOS_CP, cp.toString());
+ addNameList(obj, kvs);
+ return this;
+ }
+
+ public TapiNepHandler addSip(Uuid sipUuid) {
+ DefaultMappedServiceInterfacePoint mappedSip = new DefaultMappedServiceInterfacePoint();
+ mappedSip.serviceInterfacePointId(sipUuid);
+ obj.addToMappedServiceInterfacePoint(mappedSip);
+ return this;
+ }
+
+ public TapiNepHandler addCep(DefaultConnectionEndPoint cep) {
+ DefaultAugmentedTapiTopologyOwnedNodeEdgePoint augmentNep =
+ new DefaultAugmentedTapiTopologyOwnedNodeEdgePoint();
+ augmentNep.addToConnectionEndPoint(cep);
+ obj.addAugmentation(augmentNep);
+ return this;
+ }
+
+ public ConnectPoint getConnectPoint() {
+ return cp;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepPair.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepPair.java
new file mode 100644
index 0000000..a442586
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepPair.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.Objects;
+import java.util.stream.Stream;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * TAPI NepRef pair class for representation of endpoints of single connection.
+ */
+public class TapiNepPair {
+
+ private TapiNepRef left;
+ private TapiNepRef right;
+
+ public TapiNepPair() {
+ }
+
+ public static TapiNepPair create(TapiNepRef left, TapiNepRef right) {
+ TapiNepPair self = new TapiNepPair();
+ self.left = left;
+ self.right = right;
+ return self;
+ }
+
+ public TapiNepRef left() {
+ return left;
+ }
+
+ public TapiNepRef right() {
+ return right;
+ }
+
+ public TapiNepPair invert() {
+ return TapiNepPair.create(right, left);
+ }
+
+ public boolean isSameNode() {
+ return left.getTopologyId().equals(right.getTopologyId()) && left.getNodeId().equals(right.getNodeId());
+ }
+
+ public Stream<TapiNepRef> stream() {
+ return Stream.of(left, right);
+ }
+
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("left", left)
+ .add("right", right)
+ .toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof TapiNepPair)) {
+ return false;
+ }
+ TapiNepPair that = (TapiNepPair) o;
+ return Objects.equals(left, that.left) &&
+ Objects.equals(right, that.right);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(left, right);
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepRef.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepRef.java
index d837362..af4d299 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepRef.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepRef.java
@@ -16,21 +16,48 @@
package org.onosproject.odtn.utils.tapi;
+import java.util.Collections;
+import java.util.List;
import java.util.Optional;
import java.util.UUID;
+import java.util.stream.Collectors;
import org.onosproject.net.ConnectPoint;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.hash;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE;
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID;
+import org.onosproject.net.DeviceId;
+import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * TAPI Nep reference class.
+ *
+ * TAPI reference class should be used in ODTN ServiceApplication
+ * in order to make independent ServiceApplication implementation from DCS.
+ */
public class TapiNepRef {
+ protected final Logger log = getLogger(getClass());
+
private final UUID topologyId;
private final UUID nodeId;
private final UUID nepId;
+
+ // Annotations to be used for reference of related TAPI objects.
private UUID sipId = null;
+ private List<UUID> cepIds = Collections.emptyList();
+
+ // Annotations to be used for OpenConfig configuration.
private ConnectPoint cp = null;
+ private OdtnDeviceDescriptionDiscovery.OdtnPortType portType = null;
+ private String connectionId = null;
TapiNepRef(String topologyId, String nodeId, String nepId) {
this.topologyId = UUID.fromString(topologyId);
@@ -60,27 +87,89 @@
.orElse(null);
}
+ public List<String> getCepIds() {
+ return cepIds.stream().map(UUID::toString).collect(Collectors.toList());
+ }
+
+ public OdtnDeviceDescriptionDiscovery.OdtnPortType getPortType() {
+ return portType;
+ }
+
public ConnectPoint getConnectPoint() {
return cp;
}
+ public String getConnectionId() {
+ return connectionId;
+ }
+
+
public TapiNepRef setSipId(String sipId) {
this.sipId = UUID.fromString(sipId);
return this;
}
+ public TapiNepRef setCepIds(List<String> cepIds) {
+ this.cepIds = cepIds.stream().map(UUID::fromString).collect(Collectors.toList());
+ return this;
+ }
+
+ public TapiNepRef setPortType(String portType) {
+ this.portType = Optional.ofNullable(portType)
+ .map(OdtnDeviceDescriptionDiscovery.OdtnPortType::fromValue)
+ .orElse(null);
+ return this;
+ }
+
public TapiNepRef setConnectPoint(ConnectPoint cp) {
this.cp = cp;
return this;
}
+ public TapiNepRef setConnectionId(String connectionId) {
+ this.connectionId = connectionId;
+ return this;
+ }
+
+ /**
+ * Check if this Nep matches input filter condition.
+ *
+ * @param key Filter key
+ * @param value Filter value
+ * @return If match or not
+ */
+ public boolean is(String key, String value) {
+ checkNotNull(key);
+ checkNotNull(value);
+ switch (key) {
+ case DEVICE_ID:
+ return value.equals(
+ Optional.ofNullable(cp)
+ .map(ConnectPoint::deviceId)
+ .map(DeviceId::toString)
+ .orElse(null));
+ case ODTN_PORT_TYPE:
+ return value.equals(
+ Optional.ofNullable(portType)
+ .map(OdtnDeviceDescriptionDiscovery.OdtnPortType::value)
+ .orElse(null));
+ case CONNECTION_ID:
+ return value.equals(connectionId);
+ default:
+ log.warn("Unknown key: {}", key);
+ return true;
+ }
+ }
+
public String toString() {
return toStringHelper(getClass())
-// .add("topologyId", topologyId)
+ .add("topologyId", topologyId)
.add("nodeId", nodeId)
.add("nepId", nepId)
.add("sipId", sipId)
.add("connectPoint", cp)
+ .add("portType", portType)
+ .add("connectionId", connectionId)
.toString();
}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeHandler.java
similarity index 69%
rename from apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeBuilder.java
rename to apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeHandler.java
index 21e812c..1d897ad 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeBuilder.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeHandler.java
@@ -18,7 +18,10 @@
import java.util.HashMap;
import java.util.Map;
+
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
import org.onosproject.net.DeviceId;
@@ -31,51 +34,35 @@
import org.onosproject.yang.model.ModelObjectId;
/**
- * Utility builder class for TAPI node creation with DCS.
+ * Utility class to deal with TAPI Node with DCS.
*/
-public final class TapiNodeBuilder extends TapiInstanceBuilder {
+public final class TapiNodeHandler extends TapiObjectHandler<DefaultNode> {
private Uuid topologyUuid;
- private DefaultNode node = new DefaultNode();
- private TapiNodeBuilder() {
- setUuid(node);
+ private TapiNodeHandler() {
+ obj = new DefaultNode();
+ setId();
}
- public static TapiNodeBuilder builder() {
- return new TapiNodeBuilder();
- }
-
- public TapiNodeBuilder setTopologyUuid(Uuid topologyUuid) {
- this.topologyUuid = topologyUuid;
- return this;
- }
-
- public TapiNodeBuilder addNep(OwnedNodeEdgePoint nep) {
- node.addToOwnedNodeEdgePoint(nep);
- return this;
- }
-
- public TapiNodeBuilder setDeviceId(DeviceId deviceId) {
- Map<String, String> kvs = new HashMap<>();
- kvs.put(DEVICE_ID, deviceId.toString());
- addNameList(node, kvs);
- return this;
+ public static TapiNodeHandler create() {
+ return new TapiNodeHandler();
}
@Override
- @SuppressWarnings("unchecked")
- public DefaultNode getModelObject() {
- return node;
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
}
@Override
- public Uuid getUuid() {
- return node.uuid();
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
}
@Override
- public ModelObjectId getModelObjectId() {
+ public ModelObjectId getParentModelObjectId() {
+ checkNotNull(topologyUuid);
+
TopologyKeys topologyKey = new TopologyKeys();
topologyKey.uuid(topologyUuid);
return ModelObjectId.builder()
@@ -84,4 +71,21 @@
.build();
}
+ public TapiNodeHandler setTopologyUuid(Uuid topologyUuid) {
+ this.topologyUuid = topologyUuid;
+ return this;
+ }
+
+ public TapiNodeHandler addNep(OwnedNodeEdgePoint nep) {
+ obj.addToOwnedNodeEdgePoint(nep);
+ return this;
+ }
+
+ public TapiNodeHandler setDeviceId(DeviceId deviceId) {
+ Map<String, String> kvs = new HashMap<>();
+ kvs.put(DEVICE_ID, deviceId.toString());
+ addNameList(obj, kvs);
+ return this;
+ }
+
}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeRef.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeRef.java
index ae2a968..8db2005 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeRef.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeRef.java
@@ -21,10 +21,23 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.hash;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID;
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * TAPI Node reference class.
+ *
+ * TAPI reference class should be used in ODTN ServiceApplication
+ * in order to make independent ServiceApplication implementation from DCS.
+ */
public class TapiNodeRef {
+ protected final Logger log = getLogger(getClass());
+
private final UUID topologyId;
private final UUID nodeId;
private DeviceId deviceId;
@@ -51,9 +64,30 @@
return this;
}
+ /**
+ * Check if this Node matches input filter condition.
+ *
+ * @param key Filter key
+ * @param value Filter value
+ * @return If match or not
+ */
+ public boolean is(String key, String value) {
+ checkNotNull(value);
+ switch (key) {
+ case DEVICE_ID:
+ if (deviceId == null) {
+ return false;
+ }
+ return value.equals(deviceId.toString());
+ default:
+ log.warn("Unknown key: {}", key);
+ return true;
+ }
+ }
+
public String toString() {
return toStringHelper(getClass())
-// .add("topologyId", topologyId)
+ .add("topologyId", topologyId)
.add("nodeId", nodeId)
.add("deviceId", deviceId)
.toString();
@@ -77,4 +111,5 @@
return hash(topologyId, nodeId);
}
-}
+
+}
\ No newline at end of file
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiObjectHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiObjectHandler.java
new file mode 100644
index 0000000..05cbc57
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiObjectHandler.java
@@ -0,0 +1,258 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.List;
+import java.util.UUID;
+import org.apache.commons.lang.NotImplementedException;
+import org.onlab.util.XmlString;
+import org.onosproject.config.DynamicConfigService;
+import org.onosproject.config.Filter;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.DefaultResourceData;
+import org.onosproject.yang.model.ModelConverter;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+import org.onosproject.yang.model.ResourceData;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+import static org.onosproject.odtn.utils.YangToolUtil.toCharSequence;
+import static org.onosproject.odtn.utils.YangToolUtil.toCompositeData;
+import static org.onosproject.odtn.utils.YangToolUtil.toXmlCompositeStream;
+
+import org.onosproject.yang.model.ResourceId;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Utility abstract class to deal with TAPI ModelObject with DCS.
+ *
+ * @param <T> modelObject to be dealt with
+ */
+public abstract class TapiObjectHandler<T extends ModelObject> {
+
+ public static final String ONOS_CP = "onos-cp";
+ public static final String DEVICE_ID = "device-id";
+ public static final String ODTN_PORT_TYPE = "odtn-port-type";
+
+ protected final Logger log = getLogger(getClass());
+
+ protected ModelConverter modelConverter;
+ protected DynamicConfigService dcs;
+
+ protected T obj;
+
+ /**
+ * Get modelObject uuid.
+ *
+ * @return Uuid
+ */
+ public Uuid getId() {
+ return getIdDetail();
+ }
+
+ /**
+ * Generate and set modelObject uuid.
+ */
+ public void setId() {
+ Uuid uuid = Uuid.of(UUID.randomUUID().toString());
+ setIdDetail(uuid);
+ }
+
+ /**
+ * Set modelObject uuid.
+ *
+ * @param uuid Uuid
+ */
+ public void setId(Uuid uuid) {
+ setIdDetail(uuid);
+ }
+
+ /**
+ * Get modelObject uuid, to be implemented in sub classes.
+ *
+ * @return Uuid
+ */
+ protected abstract Uuid getIdDetail();
+
+ /**
+ * Set modelObject uuid, to be implemented in sub classes.
+ *
+ * @param uuid Uuid
+ */
+ protected abstract void setIdDetail(Uuid uuid);
+
+ /**
+ * Generate DCS modelObjectId for parent node.
+ *
+ * @return ModelObjectId of parent node
+ */
+ public abstract ModelObjectId getParentModelObjectId();
+
+ /**
+ * Get modelObject instance.
+ *
+ * @return ModelObject of target node
+ */
+ public T getModelObject() {
+ return obj;
+ }
+
+ /**
+ * Set modelObject instance.
+ *
+ * @param newObj ModelObject to be set
+ */
+ public void setModelObject(T newObj) {
+ obj = newObj;
+ }
+
+ /**
+ * Get modelObjectData instance.
+ *
+ * @return ModelObjectData of target node
+ */
+ public ModelObjectData getModelObjectData() {
+ ModelObject obj = getModelObject();
+ ModelObjectId objId = getParentModelObjectId();
+
+ return DefaultModelObjectData.builder()
+ .addModelObject(obj)
+ .identifier(objId)
+ .build();
+ }
+
+ /**
+ * Get modelObjectData instance for child node.
+ * <p>
+ * This modelObjectData is needed for read / update / delete operation
+ * to extract ResourceId of this modelObject itself.
+ * It's just workaround, fix in DCS needed.
+ *
+ * @return ModelObjectData of build target
+ */
+ public ModelObjectData getChildModelObjectData() {
+ throw new NotImplementedException();
+ }
+
+ /**
+ * Get DataNode instance.
+ *
+ * @return DataNode of target node
+ */
+ public DataNode getDataNode() {
+ ResourceData rData = toResourceData(getModelObjectData());
+ if (rData.dataNodes().size() > 1) {
+ throw new RuntimeException("Multiple dataNode found.");
+ }
+ return rData.dataNodes().get(0);
+ }
+
+ /**
+ * Read modelObject from Dcs store.
+ *
+ * @return ModelObject
+ */
+ public T read() {
+ return readOnDcs();
+ }
+
+ /**
+ * Add modelObject to Dcs store.
+ */
+ public void add() {
+ createOnDcs();
+ }
+
+ /**
+ * Delete modelObject from Dcs store.
+ */
+ public void remove() {
+ deleteOnDcs();
+ }
+
+ private void dcsSetup() {
+ dcs = getService(DynamicConfigService.class);
+ modelConverter = getService(ModelConverter.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ private T readOnDcs() {
+ dcsSetup();
+ ResourceData rData1 = toResourceData(getChildModelObjectData());
+ ResourceData rData2 = toResourceData(getModelObjectData());
+ DataNode rNode = dcs.readNode(rData1.resourceId(), Filter.builder().build());
+ obj = toModelObject(rNode, rData2.resourceId());
+ return obj;
+ }
+
+ private void createOnDcs() {
+ dcsSetup();
+ ResourceData rData = toResourceData(getModelObjectData());
+ addResourceDataToDcs(rData, rData.resourceId());
+ }
+
+ private void deleteOnDcs() {
+ dcsSetup();
+ ResourceData rData = toResourceData(getChildModelObjectData());
+ dcs.deleteNode(rData.resourceId());
+ }
+
+ private void addResourceDataToDcs(ResourceData input, ResourceId rid) {
+ if (input == null || input.dataNodes() == null) {
+ return;
+ }
+ List<DataNode> dataNodes = input.dataNodes();
+ for (DataNode node : dataNodes) {
+ dcs.createNode(rid, node);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T toModelObject(DataNode rNode, ResourceId rId) {
+ dcsSetup();
+ ResourceData rData = toResourceData(rNode, rId);
+ ModelObjectData modelObjectData = modelConverter.createModel(rData);
+ if (modelObjectData.modelObjects().size() > 1) {
+ throw new RuntimeException("Multiple modelObject found.");
+ }
+ return (T) modelObjectData.modelObjects().get(0);
+ }
+
+ private ResourceData toResourceData(DataNode rNode, ResourceId rId) {
+ return DefaultResourceData.builder()
+ .addDataNode(rNode)
+ .resourceId(rId)
+ .build();
+ }
+
+ private ResourceData toResourceData(ModelObjectData data) {
+ dcsSetup();
+ ResourceData rData = modelConverter.createDataNode(data);
+
+ // for debug
+ CharSequence strNode = toCharSequence(toXmlCompositeStream(toCompositeData(rData)));
+ log.info("XML:\n{}", XmlString.prettifyXml(strNode));
+
+ return rData;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRouteHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRouteHandler.java
new file mode 100644
index 0000000..7482979
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRouteHandler.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.DefaultRoute;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectionKeys;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnection;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.route.ConnectionEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.route.DefaultConnectionEndPoint;
+import org.onosproject.yang.model.ModelObjectId;
+
+import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.getLocalId;
+import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.setLocalId;
+
+/**
+ * Utility class to deal with TAPI Route with DCS.
+ */
+public final class TapiRouteHandler extends TapiObjectHandler<DefaultRoute> {
+
+ private Uuid connectionId;
+
+ private TapiRouteHandler() {
+ obj = new DefaultRoute();
+ setId();
+ }
+
+ public static TapiRouteHandler create() {
+ return new TapiRouteHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return Uuid.fromString(getLocalId(obj));
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setLocalId(obj, uuid.toString());
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ ConnectionKeys connectionKeys = new ConnectionKeys();
+ connectionKeys.uuid(connectionId);
+
+ return ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .addChild(DefaultConnection.class, connectionKeys)
+ .build();
+ }
+
+ public TapiRouteHandler addCep(TapiCepRef cepRef) {
+ DefaultConnectionEndPoint cep = new DefaultConnectionEndPoint();
+ cep.topologyId(cepRef.getTopologyId());
+ cep.nodeId(cepRef.getNodeId());
+ cep.ownedNodeEdgePointId(cepRef.getNepId());
+ cep.connectionEndPointId(cepRef.getCepId());
+
+ obj.addToConnectionEndPoint(cep);
+ return this;
+ }
+
+ public TapiCepRef getRouteStart() {
+ ConnectionEndPoint cep = obj.connectionEndPoint().get(0);
+ return TapiCepRef.create(cep.topologyId().toString(), cep.nodeId().toString(),
+ cep.ownedNodeEdgePointId().toString(), cep.connectionEndPointId().toString());
+ }
+
+ public TapiCepRef getRouteEnd() {
+ ConnectionEndPoint cep = obj.connectionEndPoint().get(obj.connectionEndPoint().size() - 1);
+ return TapiCepRef.create(cep.topologyId().toString(), cep.nodeId().toString(),
+ cep.ownedNodeEdgePointId().toString(), cep.connectionEndPointId().toString());
+ }
+
+ public TapiRouteHandler setConnectionId(Uuid connectionId) {
+ this.connectionId = connectionId;
+ return this;
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRpcInputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRpcInputHandler.java
new file mode 100644
index 0000000..9112f34
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRpcInputHandler.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.ModelObjectId;
+import org.onosproject.yang.model.RpcInput;
+
+/**
+ * Utility abstract class to deal with TAPI RPC input with DCS.
+ *
+ * @param <T> RPCInput modelObject to be dealt with
+ */
+public abstract class TapiRpcInputHandler<T extends ModelObject> extends TapiObjectHandler<T> {
+
+ // Uuid getter is not needed for RPC input
+ @Override
+ protected Uuid getIdDetail() {
+ return null;
+ }
+
+ // Uuid getter is not needed for RPC input
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ }
+
+ // Root modelObjectId must be used
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return ModelObjectId.builder().build();
+ }
+
+ // Cannot set InputRpc modelObject into DCS
+ @Override
+ public final void add() {
+ }
+
+ // Cannot remove InputRpc modelObject into DCS
+ @Override
+ public final void remove() {
+ }
+
+ /**
+ * Set RPCInput modelObject.
+ *
+ * @param input Tapi RpcInput modelObject
+ */
+ public void setRpcInput(RpcInput input) {
+ obj = toModelObject(input.data(), input.id());
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRpcOutputHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRpcOutputHandler.java
new file mode 100644
index 0000000..aa2c890
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiRpcOutputHandler.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility abstract class to deal with TAPI RPC output with DCS.
+ *
+ * @param <T> RpcOutput modelObject to be dealt with
+ */
+public abstract class TapiRpcOutputHandler<T extends ModelObject> extends TapiObjectHandler<T> {
+
+ // Uuid getter is not needed for RPC output
+ @Override
+ protected Uuid getIdDetail() {
+ return null;
+ }
+
+ // Uuid setter is not needed for RPC output
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ }
+
+ // Root modelObjectId must be used
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return ModelObjectId.builder().build();
+ }
+
+
+ // Cannot add OutputRpc modelObject into DCS.
+ @Override
+ public final void add() {
+ }
+
+ // Cannot delete OutputRpc modelObject into DCS.
+ @Override
+ public final void remove() {
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSepHandler.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSepHandler.java
new file mode 100644
index 0000000..35e01e0
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSepHandler.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivityservice.DefaultEndPoint;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivityserviceendpoint.DefaultServiceInterfacePoint;
+import org.onosproject.yang.model.ModelObjectId;
+
+import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.getLocalId;
+import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.setLocalId;
+
+/**
+ * Utility class to deal with TAPI SEP with DCS.
+ */
+public final class TapiSepHandler extends TapiObjectHandler<DefaultEndPoint> {
+
+ private TapiSepHandler() {
+ obj = new DefaultEndPoint();
+ setId();
+ }
+
+ public static TapiSepHandler create() {
+ return new TapiSepHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return Uuid.fromString(getLocalId(obj));
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setLocalId(obj, uuid.toString());
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return null;
+ }
+
+ public TapiSepHandler setSip(String sipId) {
+ DefaultServiceInterfacePoint sip = new DefaultServiceInterfacePoint();
+ sip.serviceInterfacePointId(sipId);
+ obj.serviceInterfacePoint(sip);
+ return this;
+ }
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipBuilder.java
deleted file mode 100644
index 5e24b33..0000000
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipBuilder.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2018-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.odtn.utils.tapi;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.onosproject.net.ConnectPoint;
-
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.LayerProtocolName;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
-
-import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
-import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
-import static org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.layerprotocolname.LayerProtocolNameEnum.DSR;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.tapicontext.DefaultServiceInterfacePoint;
-import org.onosproject.yang.model.ModelObjectId;
-
-/**
- * Utility builder class for TAPI sip creation with DCS.
- */
-public final class TapiSipBuilder extends TapiInstanceBuilder {
-
- private DefaultServiceInterfacePoint sip = new DefaultServiceInterfacePoint();
-
- private TapiSipBuilder() {
- setUuid(sip);
- }
-
- public static TapiSipBuilder builder() {
- return new TapiSipBuilder();
- }
-
- /**
- * Check this builder dealing with port for SIP or not.
- * @param cp onos connectPoint
- * @return Is this builder for SIP or not
- */
- public static boolean isSip(ConnectPoint cp) {
- // FIXME modify this method to appropriate way
- return cp.toString().contains("TRANSCEIVER");
- }
-
- public TapiSipBuilder setConnectPoint(ConnectPoint cp) {
- if (!isSip(cp)) {
- throw new IllegalStateException("Not allowed to use this port as SIP.");
- }
- Map<String, String> kvs = new HashMap<>();
- kvs.put(ONOS_CP, cp.toString());
- addNameList(sip, kvs);
- sip.addToLayerProtocolName(LayerProtocolName.of(DSR));
- return this;
- }
-
- @Override
- public ModelObjectId getModelObjectId() {
- return ModelObjectId.builder()
- .addChild(DefaultContext.class)
- .build();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public DefaultServiceInterfacePoint getModelObject() {
- return sip;
- }
-
- @Override
- public Uuid getUuid() {
- return sip.uuid();
- }
-}
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
new file mode 100644
index 0000000..34b3896
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipHandler.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.utils.tapi;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.onosproject.net.ConnectPoint;
+
+import org.onosproject.net.Port;
+import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.LayerProtocolName;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.PORT_TYPE;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
+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.rev20180307.tapicommon.layerprotocolname.LayerProtocolNameEnum.DSR;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.tapicontext.DefaultServiceInterfacePoint;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility class to deal with TAPI SIP with DCS.
+ */
+public final class TapiSipHandler extends TapiObjectHandler<DefaultServiceInterfacePoint> {
+
+ private TapiSipHandler() {
+ obj = new DefaultServiceInterfacePoint();
+ setId();
+ }
+
+ public static TapiSipHandler create() {
+ return new TapiSipHandler();
+ }
+
+ @Override
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
+ return ModelObjectId.builder()
+ .addChild(DefaultContext.class)
+ .build();
+ }
+
+ /**
+ * Check this handler dealing with port for SIP or not.
+ * @param port onos port object
+ * @return is this handler for SIP or not
+ */
+ public static boolean isSip(Port port) {
+ // FIXME modify this method to appropriate way
+ String portType = port.annotations().value(PORT_TYPE);
+ OdtnDeviceDescriptionDiscovery.OdtnPortType odtnPortType
+ = OdtnDeviceDescriptionDiscovery.OdtnPortType.fromValue(portType);
+ return odtnPortType.value().equals(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value());
+ }
+
+ 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);
+ }
+
+ public TapiSipHandler setConnectPoint(ConnectPoint cp) {
+ Map<String, String> kvs = new HashMap<>();
+ kvs.put(ONOS_CP, cp.toString());
+ addNameList(obj, kvs);
+ obj.addToLayerProtocolName(LayerProtocolName.of(DSR));
+ return this;
+ }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyHandler.java
similarity index 67%
rename from apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyBuilder.java
rename to apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyHandler.java
index 4c96133..2d81e80 100644
--- a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyBuilder.java
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyHandler.java
@@ -16,6 +16,7 @@
package org.onosproject.odtn.utils.tapi;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
@@ -25,40 +26,34 @@
import org.onosproject.yang.model.ModelObjectId;
/**
- * Utility builder class for TAPI topology creation with DCS.
+ * Utility class to deal with TAPI Topology with DCS.
*/
-public final class TapiTopologyBuilder extends TapiInstanceBuilder {
+public final class TapiTopologyHandler extends TapiObjectHandler<DefaultTopology> {
- private DefaultTopology topology;
-
- private TapiTopologyBuilder(DefaultTopology topology) {
- this.topology = topology;
- setUuid(this.topology);
+ private TapiTopologyHandler() {
+ obj = new DefaultTopology();
+ setId();
}
- public static TapiTopologyBuilder builder(DefaultTopology topology) {
- return new TapiTopologyBuilder(topology);
+ public static TapiTopologyHandler create() {
+ return new TapiTopologyHandler();
}
-
@Override
- public ModelObjectId getModelObjectId() {
+ protected Uuid getIdDetail() {
+ return getUuid(obj);
+ }
+ @Override
+ protected void setIdDetail(Uuid uuid) {
+ setUuid(obj, uuid);
+ }
+
+ @Override
+ public ModelObjectId getParentModelObjectId() {
DefaultAugmentedTapiCommonContext topologyContext = new DefaultAugmentedTapiCommonContext();
- topologyContext.addToTopology(topology);
+ topologyContext.addToTopology(obj);
return ModelObjectId.builder().addChild(DefaultContext.class).build();
}
-
- @Override
- @SuppressWarnings("unchecked")
- public DefaultTopology getModelObject() {
- return topology;
- }
-
- @Override
- public Uuid getUuid() {
- return topology.uuid();
- }
-
}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiResolver.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/TapiResolver.java
similarity index 71%
rename from apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiResolver.java
rename to apps/odtn/service/src/main/java/org/onosproject/odtn/TapiResolver.java
index 5311cd9..2c2f271 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiResolver.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/TapiResolver.java
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-package org.onosproject.odtn.internal;
+package org.onosproject.odtn;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.ElementId;
@@ -70,13 +71,39 @@
TapiNodeRef getNodeRef(ElementId deviceId);
/**
+ * Resolve TAPI node with Node unique keys.
+ *
+ * @param nodeRef Node reference object which has node unique keys.
+ * @return TapiNodeRef
+ * @throws NoSuchElementException if target not found
+ */
+ TapiNodeRef getNodeRef(TapiNodeRef nodeRef);
+
+ /**
* Get all NodeRefs.
*
- * @return List<TapiNodeRef>
+ * @return List of all NodeRefs
*/
List<TapiNodeRef> getNodeRefs();
/**
+ * Apply filter and get filtered NodeRefs.
+ *
+ * @param filter key value map for filter
+ * @return List of filtered NodeRefs, which matches all of {@code filter}
+ */
+ List<TapiNodeRef> getNodeRefs(Map<String, String> filter);
+
+ /**
+ * Resolve TAPI nep with Nep unique keys.
+ *
+ * @param nepRef Nep reference object which has Nep unique keys.
+ * @return TapiNepRef
+ * @throws NoSuchElementException if target not found
+ */
+ TapiNepRef getNepRef(TapiNepRef nepRef);
+
+ /**
* Resolve TAPI nep associated with ConnectPoint.
*
* @param cp search key
@@ -97,11 +124,19 @@
/**
* Get all NepRefs.
*
- * @return List<TapiNepRef>
+ * @return List of all NepRefs
*/
List<TapiNepRef> getNepRefs();
/**
+ * Apply filter and get filtered NepRefs.
+ *
+ * @param filter key value map for filter
+ * @return List of filtered NepRefs, which matches all of {@code filter}
+ */
+ List<TapiNepRef> getNepRefs(Map<String, String> filter);
+
+ /**
* Inform the cache is already got dirty and let it update cache.
* The cache update process is conducted when next resolve request
* (hasXXX or getXXX) comes.
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiTopologyManager.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/TapiTopologyManager.java
similarity index 95%
rename from apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiTopologyManager.java
rename to apps/odtn/service/src/main/java/org/onosproject/odtn/TapiTopologyManager.java
index 1be4ed5..bea4a20 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiTopologyManager.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/TapiTopologyManager.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.odtn.internal;
+package org.onosproject.odtn;
import org.onosproject.net.Device;
import org.onosproject.net.Link;
@@ -27,36 +27,42 @@
/**
* DEVICE_ADDED event handler.
+ *
* @param device device to be added
*/
void addDevice(Device device);
/**
* DEVICE_REMOVED event handler.
+ *
* @param device device to be removed
*/
void removeDevice(Device device);
/**
* LINK_ADDED event handler.
+ *
* @param link link to be added
*/
void addLink(Link link);
/**
* LINK_REMOVED event handler.
+ *
* @param link link to be removed
*/
void removeLink(Link link);
/**
* PORT_ADDED event handler.
+ *
* @param port port to be added
*/
void addPort(Port port);
/**
* PORT_REMOVED event handler.
+ *
* @param port port to be removed
*/
void removePort(Port port);
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/impl/ServiceApplicationComponent.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/impl/ServiceApplicationComponent.java
index 2a92137..48057c8 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/impl/ServiceApplicationComponent.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/impl/ServiceApplicationComponent.java
@@ -20,68 +20,41 @@
package org.onosproject.odtn.impl;
-import java.util.List;
-
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onosproject.config.DynamicConfigEvent;
-import org.onosproject.config.DynamicConfigListener;
-import org.onosproject.config.DynamicConfigService;
-import org.onosproject.config.FailedException;
-import org.onosproject.config.Filter;
import org.onosproject.net.Link;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.NetworkConfigStoreDelegate;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.link.LinkListener;
import org.onosproject.net.link.LinkService;
+import org.onosproject.odtn.TapiResolver;
+import org.onosproject.odtn.TapiTopologyManager;
+import org.onosproject.odtn.internal.DcsBasedTapiCommonRpc;
+import org.onosproject.odtn.internal.DcsBasedTapiConnectivityRpc;
import org.onosproject.odtn.internal.DcsBasedTapiDataProducer;
import org.onosproject.odtn.internal.TapiDataProducer;
-import org.onosproject.odtn.internal.TapiResolver;
-import org.onosproject.odtn.internal.TapiTopologyManager;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.TapiCommonService;
-import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.getserviceinterfacepointlist.DefaultGetServiceInterfacePointListOutput;
-import org.onosproject.yang.model.NodeKey;
-import org.onosproject.yang.model.SchemaId;
+import org.onosproject.store.AbstractStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.TapiConnectivityService;
-import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.
- tapiconnectivity.createconnectivityservice.CreateConnectivityServiceInput;
-
-import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.
- tapiconnectivity.createconnectivityservice.createconnectivityserviceinput.EndPoint;
-
-
-
-// onos-yang-tools
-import org.onosproject.yang.model.DataNode;
-
-import org.onosproject.yang.model.ResourceData;
-import org.onosproject.yang.model.DefaultResourceData;
-import org.onosproject.yang.model.ModelObject;
-import org.onosproject.yang.model.ModelObjectData;
-import org.onosproject.yang.model.ModelConverter;
-
-import org.onosproject.yang.model.ResourceId;
-
+// DCS / onos-yang-tools
+import org.onosproject.config.DynamicConfigEvent;
+import org.onosproject.config.DynamicConfigListener;
+import org.onosproject.config.DynamicConfigService;
import org.onosproject.yang.model.RpcRegistry;
-import org.onosproject.yang.model.RpcService;
-import org.onosproject.yang.model.RpcInput;
-import org.onosproject.yang.model.RpcOutput;
-import org.onosproject.yang.model.SchemaContextProvider;
-import org.onosproject.yang.runtime.YangRuntimeService;
import static org.onosproject.config.DynamicConfigEvent.Type.NODE_ADDED;
import static org.onosproject.config.DynamicConfigEvent.Type.NODE_DELETED;
-import static org.onosproject.odtn.utils.YangToolUtil.toDataNode;
/**
* OSGi Component for ODTN Service application.
@@ -104,18 +77,9 @@
protected NetworkConfigService netcfgService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected YangRuntimeService yangRuntime;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected SchemaContextProvider schemaContextProvider;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RpcRegistry rpcRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ModelConverter modelConverter;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TapiTopologyManager tapiTopologyManager;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -127,14 +91,13 @@
private DeviceListener deviceListener = new InternalDeviceListener();
private final LinkListener linkListener = new InternalLinkListener();
+ private final NetworkConfigListener netcfgListener = new InternalNetCfgListener();
private TapiDataProducer dataProvider = new DcsBasedTapiDataProducer();
+ private InternalNetCfgManager netcfgStore = new InternalNetCfgManager();
// Rpc Service for TAPI Connectivity
- private final RpcService rpcTapiConnectivity =
- new TapiConnectivityRpc();
-
- private final RpcService rpcTapiCommon =
- new TapiCommonRpc();
+ private final DcsBasedTapiConnectivityRpc rpcTapiConnectivity = new DcsBasedTapiConnectivityRpc();
+ private final DcsBasedTapiCommonRpc rpcTapiCommon = new DcsBasedTapiCommonRpc();
@Activate
@@ -143,8 +106,11 @@
dynConfigService.addListener(dynamicConfigServiceListener);
deviceService.addListener(deviceListener);
linkService.addListener(linkListener);
+ netcfgService.addListener(netcfgListener);
rpcRegistry.registerRpcService(rpcTapiConnectivity);
rpcRegistry.registerRpcService(rpcTapiCommon);
+ rpcTapiConnectivity.init();
+ rpcTapiCommon.init();
}
@@ -153,6 +119,7 @@
log.info("Stopped");
rpcRegistry.unregisterRpcService(rpcTapiCommon);
rpcRegistry.unregisterRpcService(rpcTapiConnectivity);
+ netcfgService.removeListener(netcfgListener);
linkService.removeListener(linkListener);
deviceService.removeListener(deviceListener);
dynConfigService.removeListener(dynamicConfigServiceListener);
@@ -172,6 +139,8 @@
@Override
public void event(DeviceEvent event) {
+ netcfgStore.post(event);
+
switch (event.type()) {
case DEVICE_ADDED:
tapiTopologyManager.addDevice(event.subject());
@@ -222,6 +191,36 @@
}
/**
+ * Representation of internal listener, listening for netcfg event.
+ */
+ private class InternalNetCfgListener implements NetworkConfigListener {
+
+ /**
+ * Process an Event from the NetCfg Service.
+ *
+ * @param event link event
+ */
+ @Override
+ public void event(NetworkConfigEvent event) {
+// Object config = event.subject();
+ log.info("config: {}", event.subject());
+ log.info("type: {}", event.type());
+ }
+ }
+
+ private class InternalNetCfgManager
+ extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> {
+
+ public void post(Object obj) {
+ log.info("Post netcfg event : {}", obj);
+ NetworkConfigEvent.Type type = NetworkConfigEvent.Type.CONFIG_UPDATED;
+ notifyDelegate(new NetworkConfigEvent(type, obj, obj.getClass()));
+ }
+
+ }
+
+
+ /**
* Representation of internal listener, listening for dynamic config event.
*/
private class InternalDynamicConfigListener implements DynamicConfigListener {
@@ -251,237 +250,74 @@
@Override
public void event(DynamicConfigEvent event) {
resolver.makeDirty();
-
- ResourceId rsId = event.subject();
- DataNode node;
- try {
- Filter filter = Filter.builder().addCriteria(rsId).build();
- node = dynConfigService.readNode(rsId, filter);
- } catch (FailedException e) {
- node = null;
- }
- switch (event.type()) {
- case NODE_ADDED:
- onDcsNodeAdded(rsId, node);
- break;
-
- case NODE_DELETED:
- onDcsNodeDeleted(node);
- break;
-
- default:
- log.warn("Unknown Event", event.type());
- break;
- }
+// ResourceId rsId = event.subject();
+// DataNode node;
+// try {
+// Filter filter = Filter.builder().addCriteria(rsId).build();
+// node = dynConfigService.readNode(rsId, filter);
+// } catch (FailedException e) {
+// node = null;
+// }
+// switch (event.type()) {
+// case NODE_ADDED:
+// onDcsNodeAdded(rsId, node);
+// break;
+//
+// case NODE_DELETED:
+// onDcsNodeDeleted(node);
+// break;
+//
+// default:
+// log.warn("Unknown Event", event.type());
+// break;
+// }
}
- /**
- * Process the event that a node has been added to the DCS.
- *
- * @param rsId ResourceId of the added node
- * @param node added node. Access the key and value
- */
- private void onDcsNodeAdded(ResourceId rsId, DataNode node) {
-
- switch (node.type()) {
- case SINGLE_INSTANCE_NODE:
- break;
- case MULTI_INSTANCE_NODE:
- break;
- case SINGLE_INSTANCE_LEAF_VALUE_NODE:
- break;
- case MULTI_INSTANCE_LEAF_VALUE_NODE:
- break;
- default:
- break;
- }
-
- NodeKey dataNodeKey = node.key();
- SchemaId schemaId = dataNodeKey.schemaId();
+// /**
+// * Process the event that a node has been added to the DCS.
+// *
+// * @param rsId ResourceId of the added node
+// * @param node added node. Access the key and value
+// */
+// private void onDcsNodeAdded(ResourceId rsId, DataNode node) {
+//
+// switch (node.type()) {
+// case SINGLE_INSTANCE_NODE:
+// break;
+// case MULTI_INSTANCE_NODE:
+// break;
+// case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+// break;
+// case MULTI_INSTANCE_LEAF_VALUE_NODE:
+// break;
+// default:
+// break;
+// }
+//
+// NodeKey dataNodeKey = node.key();
+// SchemaId schemaId = dataNodeKey.schemaId();
// Consolidate events
// if (!schemaId.namespace().contains("tapi")) {
// return;
// }
// log.info("namespace {}", schemaId.namespace());
- }
+// }
- /**
- * Process the event that a node has been deleted from the DCS.
- *
- * @param dataNode data node
- */
- private void onDcsNodeDeleted(DataNode dataNode) {
- // TODO: Implement release logic
- }
+// /**
+// * Process the event that a node has been deleted from the DCS.
+// *
+// * @param dataNode data node
+// */
+// private void onDcsNodeDeleted(DataNode dataNode) {
+// // TODO: Implement release logic
+// }
}
- private class TapiConnectivityRpc implements TapiConnectivityService {
- /**
- * Service interface of createConnectivityService.
- *
- * @param inputVar input of service interface createConnectivityService
- * @return rpcOutput output of service interface createConnectivityService
- */
- @Override
- public RpcOutput createConnectivityService(RpcInput inputVar) {
-
- DataNode data = inputVar.data();
- ResourceId rid = inputVar.id();
-
- log.info("RpcInput Data {}", data);
- log.info("RpcInput ResourceId {}", rid);
-
- for (ModelObject mo : getModelObjects(data, rid)) {
- if (mo instanceof CreateConnectivityServiceInput) {
- CreateConnectivityServiceInput i = (CreateConnectivityServiceInput) mo;
- log.info("i {}", i);
- List<EndPoint> epl = i.endPoint();
- for (EndPoint ep : epl) {
- log.info("ep {}", ep);
- }
- }
- }
-
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
- }
-
-
- /**
- * Service interface of deleteConnectivityService.
- *
- * @param inputVar input of service interface deleteConnectivityService
- * @return rpcOutput output of service interface deleteConnectivityService
- */
- @Override
- public RpcOutput deleteConnectivityService(RpcInput inputVar) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
- }
-
-
- /**
- * Service interface of getConnectionDetails.
- *
- * @param inputVar input of service interface getConnectionDetails
- * @return rpcOutput output of service interface getConnectionDetails
- */
- @Override
- public RpcOutput getConnectionDetails(RpcInput inputVar) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
-
- }
-
- /**
- * Service interface of getConnectivityServiceList.
- *
- * @param inputVar input of service interface getConnectivityServiceList
- * @return rpcOutput output of service interface getConnectivityServiceList
- */
- @Override
- public RpcOutput getConnectivityServiceList(RpcInput inputVar) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
-
- }
-
- /**
- * Service interface of getConnectivityServiceDetails.
- *
- * @param inputVar input of service interface getConnectivityServiceDetails
- * @return rpcOutput output of service interface getConnectivityServiceDetails
- */
- @Override
- public RpcOutput getConnectivityServiceDetails(RpcInput inputVar) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
-
- }
-
-
- /**
- * Service interface of updateConnectivityService.
- *
- * @param inputVar input of service interface updateConnectivityService
- * @return rpcOutput output of service interface updateConnectivityService
- */
- @Override
- public RpcOutput updateConnectivityService(RpcInput inputVar) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
-
- }
-
-
- private ResourceData createResourceData(DataNode dataNode, ResourceId resId) {
- return DefaultResourceData.builder()
- .addDataNode(dataNode)
- .resourceId(resId)
- .build();
- }
-
- /**
- * Returns model objects of the store.
- *
- * @param dataNode data node from store
- * @param resId parent resource id
- * @return model objects
- */
- private List<ModelObject> getModelObjects(DataNode dataNode, ResourceId resId) {
- ResourceData data = createResourceData(dataNode, resId);
- ModelObjectData modelData = modelConverter.createModel(data);
- return modelData.modelObjects();
- }
-
-
- }
-
-
- private class TapiCommonRpc implements TapiCommonService {
-
- /**
- * Service interface of getServiceInterfacePointDetails.
- *
- * @param rpcInput input of service interface getServiceInterfacePointDetails
- * @return rpcOutput output of service interface getServiceInterfacePointDetails
- */
- @Override
- public RpcOutput getServiceInterfacePointDetails(RpcInput rpcInput) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
- }
-
- /**
- * Service interface of getServiceInterfacePointList.
- *
- * @param rpcInput input of service interface getServiceInterfacePointList
- * @return rpcOutput output of service interface getServiceInterfacePointList
- */
- @Override
- public RpcOutput getServiceInterfacePointList(RpcInput rpcInput) {
-
- DataNode data = rpcInput.data();
- ResourceId rid = rpcInput.id();
-
- log.info("RpcInput Data {}", data);
- log.info("RpcInput ResourceId {}", rid);
-
- DefaultGetServiceInterfacePointListOutput node = new DefaultGetServiceInterfacePointListOutput();
- DataNode dnode = toDataNode(node);
-
- return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, dnode);
- }
-
- /**
- * Service interface of updateServiceInterfacePoint.
-q *
- * @param rpcInput input of service interface updateServiceInterfacePoint
- * @return rpcOutput output of service interface updateServiceInterfacePoint
- */
- @Override
- public RpcOutput updateServiceInterfacePoint(RpcInput rpcInput) {
- return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
- }
- }
}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiCommonRpc.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiCommonRpc.java
new file mode 100644
index 0000000..315e10c
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiCommonRpc.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.internal;
+
+import org.onosproject.config.DynamicConfigService;
+import org.onosproject.odtn.TapiResolver;
+import org.onosproject.odtn.utils.tapi.TapiGetSipListOutputHandler;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.TapiCommonService;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.model.ModelConverter;
+import org.onosproject.yang.model.RpcInput;
+import org.onosproject.yang.model.RpcOutput;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+
+/**
+ * DCS-dependent tapi-common yang RPCs implementation.
+ */
+public class DcsBasedTapiCommonRpc implements TapiCommonService {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ protected DynamicConfigService dcs;
+ protected ModelConverter modelConverter;
+ protected TapiResolver resolver;
+
+ public void init() {
+ dcs = getService(DynamicConfigService.class);
+ modelConverter = getService(ModelConverter.class);
+ resolver = getService(TapiResolver.class);
+ }
+
+ /**
+ * Service interface of getServiceInterfacePointDetails.
+ *
+ * @param rpcInput input of service interface getServiceInterfacePointDetails
+ * @return rpcOutput output of service interface getServiceInterfacePointDetails
+ */
+ @Override
+ public RpcOutput getServiceInterfacePointDetails(RpcInput rpcInput) {
+ log.error("Not implemented");
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+
+ /**
+ * Service interface of getServiceInterfacePointList.
+ *
+ * @param rpcInput input of service interface getServiceInterfacePointList
+ * @return rpcOutput output of service interface getServiceInterfacePointList
+ */
+ @Override
+ public RpcOutput getServiceInterfacePointList(RpcInput rpcInput) {
+
+ try {
+ TapiGetSipListOutputHandler output = TapiGetSipListOutputHandler.create();
+
+ resolver.getNepRefs().stream()
+ .filter(nepRef -> nepRef.getSipId() != null)
+ .forEach(nepRef -> {
+ output.addSip(Uuid.fromString(nepRef.getSipId()));
+ });
+
+ return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
+ } catch (Throwable e) {
+ log.error("Error:", e);
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+
+ }
+
+ /**
+ * Service interface of updateServiceInterfacePoint.
+ *
+ * @param rpcInput input of service interface updateServiceInterfacePoint
+ * @return rpcOutput output of service interface updateServiceInterfacePoint
+ */
+ @Override
+ public RpcOutput updateServiceInterfacePoint(RpcInput rpcInput) {
+ log.error("Not implemented");
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+}
+
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectionManager.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectionManager.java
new file mode 100644
index 0000000..6ddb662
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectionManager.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.config.FailedException;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.odtn.utils.tapi.TapiConnection;
+import org.onosproject.odtn.utils.tapi.TapiNepPair;
+import org.onosproject.odtn.utils.tapi.TapiCepRefHandler;
+import org.onosproject.odtn.utils.tapi.TapiConnectionHandler;
+
+import org.onosproject.odtn.utils.tapi.TapiRouteHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+
+/**
+ * DCS-dependent Tapi connection manager implementation.
+ */
+public class DcsBasedTapiConnectionManager implements TapiConnectionManager {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ protected TapiPathComputer connectionController;
+ private DeviceService deviceService;
+
+ private List<DcsBasedTapiConnectionManager> connectionManagerList = new ArrayList<>();
+ private TapiConnectionHandler connectionHandler = TapiConnectionHandler.create();
+ private Operation op = null;
+
+
+ enum Operation {
+ CREATE,
+ DELETE
+ }
+
+ public static DcsBasedTapiConnectionManager create() {
+ DcsBasedTapiConnectionManager self = new DcsBasedTapiConnectionManager();
+ self.connectionController = DefaultTapiPathComputer.create();
+ self.deviceService = getService(DeviceService.class);
+ return self;
+ }
+
+ @Override
+ public TapiConnectionHandler createConnection(TapiNepPair neps) {
+
+ // Calculate route
+ TapiConnection connection = connectionController.pathCompute(neps);
+ log.info("Calculated path: {}", connection);
+
+ createConnectionRecursively(connection);
+ return connectionHandler;
+ }
+
+ @Override
+ public void deleteConnection(TapiConnectionHandler connectionHandler) {
+
+ // read target to be deleted
+ this.connectionHandler = connectionHandler;
+ this.connectionHandler.read();
+ log.info("model: {}", connectionHandler.getModelObject());
+
+ deleteConnectionRecursively(connectionHandler);
+ }
+
+ @Override
+ public void apply() {
+ connectionManagerList.forEach(DcsBasedTapiConnectionManager::apply);
+ switch (op) {
+ case CREATE:
+ connectionHandler.add();
+ break;
+ case DELETE:
+ connectionHandler.remove();
+ break;
+ default:
+ throw new FailedException("Unknown operation type.");
+ }
+ }
+
+ /**
+ * Generate TAPI connection and its under connections recursively
+ * and add them to creation queue.
+ *
+ * @param connection connection to be created
+ */
+ private void createConnectionRecursively(TapiConnection connection) {
+ op = Operation.CREATE;
+ connectionManagerList.clear();
+
+ TapiRouteHandler routeBuilder = TapiRouteHandler.create();
+
+ // Create under connection, and set them into routeBuilder
+ connection.getLowerConnections().forEach(lowerConnection -> {
+ delegateConnectionCreation(lowerConnection);
+ routeBuilder.addCep(lowerConnection.getCeps().left());
+ routeBuilder.addCep(lowerConnection.getCeps().right());
+ });
+
+ connectionHandler.addRoute(routeBuilder.getModelObject());
+
+ connectionHandler.addCep(TapiCepRefHandler.create()
+ .setCep(connection.getCeps().left()).getModelObject());
+ connectionHandler.addCep(TapiCepRefHandler.create()
+ .setCep(connection.getCeps().right()).getModelObject());
+
+ connectionManagerList.forEach(manager ->
+ connectionHandler.addLowerConnection(manager.getConnectionHandler().getModelObject()));
+
+ }
+
+ /**
+ * Generate TAPI connection and its under connections recursively
+ * and add them to deletion queue.
+ *
+ * @param connectionHandler connectionHandler of connection to be deleted
+ */
+ private void deleteConnectionRecursively(TapiConnectionHandler connectionHandler) {
+ op = Operation.DELETE;
+ connectionManagerList.clear();
+
+ this.connectionHandler = connectionHandler;
+ this.connectionHandler.getLowerConnections().forEach(lowerConnectionHandler -> {
+ delegateConnectionDeletion(lowerConnectionHandler);
+ });
+ }
+
+ /**
+ * Delegate lower-connection creation to other corresponding TapiConnectionManager of each Nodes.
+ *
+ * @param connection connection to be created
+ */
+ private void delegateConnectionCreation(TapiConnection connection) {
+ log.info("ceps: {}", connection.getCeps());
+ DcsBasedTapiConnectionManager manager = DcsBasedTapiConnectionManager.create();
+ manager.createConnectionRecursively(connection);
+ connectionManagerList.add(manager);
+ }
+
+ /**
+ * Delegate lower-connection deletion to other corresponding TapiConnectionManager of each Nodes.
+ *
+ * @param connectionHandler connectionHandler of connection to be deleted
+ */
+ private void delegateConnectionDeletion(TapiConnectionHandler connectionHandler) {
+ log.info("model: {}", connectionHandler.getModelObject());
+ DcsBasedTapiConnectionManager manager = DcsBasedTapiConnectionManager.create();
+ manager.deleteConnectionRecursively(connectionHandler);
+ connectionManagerList.add(manager);
+ }
+
+
+ public TapiConnectionHandler getConnectionHandler() {
+ return connectionHandler;
+ }
+
+}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java
new file mode 100644
index 0000000..2598781
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiConnectivityRpc.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.internal;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import org.onosproject.config.DynamicConfigService;
+import org.onosproject.odtn.TapiResolver;
+import org.onosproject.odtn.utils.tapi.TapiNepPair;
+import org.onosproject.odtn.utils.tapi.TapiConnectionHandler;
+import org.onosproject.odtn.utils.tapi.TapiConnectivityServiceHandler;
+import org.onosproject.odtn.utils.tapi.TapiContextHandler;
+import org.onosproject.odtn.utils.tapi.TapiCreateConnectivityInputHandler;
+import org.onosproject.odtn.utils.tapi.TapiCreateConnectivityOutputHandler;
+import org.onosproject.odtn.utils.tapi.TapiDeleteConnectivityInputHandler;
+import org.onosproject.odtn.utils.tapi.TapiDeleteConnectivityOutputHandler;
+import org.onosproject.odtn.utils.tapi.TapiGetConnectivityDetailsInputHandler;
+import org.onosproject.odtn.utils.tapi.TapiGetConnectivityDetailsOutputHandler;
+import org.onosproject.odtn.utils.tapi.TapiGetConnectivityListOutputHandler;
+import org.onosproject.odtn.utils.tapi.TapiNepRef;
+import org.onosproject.odtn.utils.tapi.TapiObjectHandler;
+import org.onosproject.odtn.utils.tapi.TapiSepHandler;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.TapiConnectivityService;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnectivityService;
+import org.onosproject.yang.model.ModelConverter;
+import org.onosproject.yang.model.RpcInput;
+import org.onosproject.yang.model.RpcOutput;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+
+
+/**
+ * DCS-dependent tapi-connectivity yang RPCs implementation.
+ */
+public class DcsBasedTapiConnectivityRpc implements TapiConnectivityService {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ protected DynamicConfigService dcs;
+ protected ModelConverter modelConverter;
+ protected TapiResolver resolver;
+
+ public void init() {
+ dcs = getService(DynamicConfigService.class);
+ modelConverter = getService(ModelConverter.class);
+ resolver = getService(TapiResolver.class);
+ }
+
+ /**
+ * Service interface of createConnectivityService.
+ *
+ * @param inputVar input of service interface createConnectivityService
+ * @return output of service interface createConnectivityService
+ */
+ @Override
+ public RpcOutput createConnectivityService(RpcInput inputVar) {
+
+ try {
+ TapiCreateConnectivityInputHandler input = new TapiCreateConnectivityInputHandler();
+ input.setRpcInput(inputVar);
+ // TODO validation check
+ log.info("input SIPs: {}", input.getSips());
+
+ List<TapiNepRef> nepRefs = input.getSips().stream()
+ .map(sipId -> resolver.getNepRef(sipId))
+ .collect(Collectors.toList());
+ // for test
+// Map<String, String> filter = new HashMap<>();
+// filter.put(ODTN_PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value());
+// List<TapiNepRef> nepRefs = resolver.getNepRefs(filter);
+
+ // setup connections
+ TapiNepPair neps = TapiNepPair.create(nepRefs.get(0), nepRefs.get(1));
+ DcsBasedTapiConnectionManager connectionManager = DcsBasedTapiConnectionManager.create();
+ connectionManager.createConnection(neps);
+
+ // setup connectivity service
+ TapiConnectivityServiceHandler connectivityServiceHandler = TapiConnectivityServiceHandler.create();
+ connectivityServiceHandler.addConnection(connectionManager.getConnectionHandler().getModelObject().uuid());
+ neps.stream()
+ .map(nepRef -> TapiSepHandler.create().setSip(nepRef.getSipId()))
+ .forEach(sepBuilder -> {
+ connectivityServiceHandler.addSep(sepBuilder.getModelObject());
+ });
+
+ // build
+ connectionManager.apply();
+ connectivityServiceHandler.add();
+
+ // output
+ TapiCreateConnectivityOutputHandler output = TapiCreateConnectivityOutputHandler.create()
+ .addService(connectivityServiceHandler.getModelObject());
+ return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
+
+ } catch (Throwable e) {
+ log.error("Error:", e);
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+
+ }
+
+
+ /**
+ * Service interface of deleteConnectivityService.
+ *
+ * @param inputVar input of service interface deleteConnectivityService
+ * @return output of service interface deleteConnectivityService
+ */
+ @Override
+ public RpcOutput deleteConnectivityService(RpcInput inputVar) {
+
+ try {
+ TapiDeleteConnectivityInputHandler input = new TapiDeleteConnectivityInputHandler();
+ input.setRpcInput(inputVar);
+ log.info("input serviceId: {}", input.getId());
+
+ TapiConnectivityServiceHandler serviceHandler = TapiConnectivityServiceHandler.create();
+ serviceHandler.setId(input.getId());
+
+ DefaultConnectivityService service = serviceHandler.read();
+
+ service.connection().stream().forEach(connection -> {
+ TapiConnectionHandler connectionHandler = TapiConnectionHandler.create();
+ connectionHandler.setId(Uuid.fromString(connection.connectionId().toString()));
+ DcsBasedTapiConnectionManager manager = DcsBasedTapiConnectionManager.create();
+ manager.deleteConnection(connectionHandler);
+ manager.apply();
+ });
+ serviceHandler.remove();
+
+ TapiDeleteConnectivityOutputHandler output = TapiDeleteConnectivityOutputHandler.create()
+ .addService(serviceHandler.getModelObject());
+
+ return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
+ } catch (Throwable e) {
+ log.error("Error:", e);
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+ }
+
+ /**
+ * Service interface of updateConnectivityService.
+ *
+ * @param inputVar input of service interface updateConnectivityService
+ * @return output of service interface updateConnectivityService
+ */
+ @Override
+ public RpcOutput updateConnectivityService(RpcInput inputVar) {
+ log.error("Not implemented");
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+
+ }
+
+ /**
+ * Service interface of getConnectivityServiceList.
+ *
+ * @param inputVar input of service interface getConnectivityServiceList
+ * @return output of service interface getConnectivityServiceList
+ */
+ @Override
+ public RpcOutput getConnectivityServiceList(RpcInput inputVar) {
+
+ try {
+ TapiGetConnectivityListOutputHandler output = TapiGetConnectivityListOutputHandler.create();
+ log.info("get list called");
+
+ TapiContextHandler handler = TapiContextHandler.create();
+ handler.read();
+ log.info("model : {}", handler.getModelObject());
+ log.info("conserv : {}", handler.getConnectivityServices());
+
+ handler.getConnectivityServices().stream()
+ .map(TapiObjectHandler::getModelObject)
+ .forEach(output::addService);
+
+ return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
+
+ } catch (Throwable e) {
+ log.error("Error:", e);
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+ }
+
+
+ /**
+ * Service interface of getConnectivityServiceDetails.
+ *
+ * @param inputVar input of service interface getConnectivityServiceDetails
+ * @return output of service interface getConnectivityServiceDetails
+ */
+ @Override
+ public RpcOutput getConnectivityServiceDetails(RpcInput inputVar) {
+
+ try {
+ TapiGetConnectivityDetailsInputHandler input = new TapiGetConnectivityDetailsInputHandler();
+ input.setRpcInput(inputVar);
+ log.info("input serviceId: {}", input.getId());
+
+ TapiConnectivityServiceHandler handler = TapiConnectivityServiceHandler.create();
+ handler.setId(input.getId());
+ handler.read();
+
+ TapiGetConnectivityDetailsOutputHandler output = TapiGetConnectivityDetailsOutputHandler.create()
+ .addService(handler.getModelObject());
+
+ return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
+
+ } catch (Throwable e) {
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+
+ }
+
+ /**
+ * Service interface of getConnectionDetails.
+ *
+ * @param inputVar input of service interface getConnectionDetails
+ * @return output of service interface getConnectionDetails
+ */
+ @Override
+ public RpcOutput getConnectionDetails(RpcInput inputVar) {
+ log.error("Not implemented");
+ return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
+ }
+
+}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducer.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducer.java
index 5f6b96c..726d002 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducer.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducer.java
@@ -15,9 +15,12 @@
*/
package org.onosproject.odtn.internal;
+
import com.google.common.annotations.VisibleForTesting;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import org.onosproject.config.DynamicConfigService;
@@ -30,14 +33,13 @@
import org.onosproject.odtn.utils.tapi.TapiNodeRef;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.globalclass.Name;
+import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.context.topology.node.ownednodeedgepoint.DefaultAugmentedTapiTopologyOwnedNodeEdgePoint;
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.context.DefaultAugmentedTapiCommonContext;
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.Topology;
-import org.onosproject.yang.model.Augmentable;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultModelObjectData;
import org.onosproject.yang.model.DefaultResourceData;
import org.onosproject.yang.model.ModelConverter;
-import org.onosproject.yang.model.ModelObject;
import org.onosproject.yang.model.ModelObjectData;
import org.onosproject.yang.model.ModelObjectId;
import org.onosproject.yang.model.ResourceData;
@@ -45,13 +47,19 @@
import org.slf4j.Logger;
import static org.onlab.osgi.DefaultServiceDirectory.getService;
-import static org.onosproject.odtn.utils.tapi.TapiInstanceBuilder.DEVICE_ID;
-import static org.onosproject.odtn.utils.tapi.TapiInstanceBuilder.ONOS_CP;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ONOS_CP;
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID;
import static org.slf4j.LoggerFactory.getLogger;
+/**
+ * DCS-dependent Tapi Data producer implementation.
+ */
public class DcsBasedTapiDataProducer implements TapiDataProducer {
private final Logger log = getLogger(getClass());
+
protected DynamicConfigService dcs;
protected ModelConverter modelConverter;
@@ -63,17 +71,28 @@
@Override
public void updateCacheRequest(DefaultTapiResolver resolver) {
- ModelObject context = readContextModelObject();
- updateCache(resolver, context);
+ updateCache(resolver, readContextModelObject());
}
+ /**
+ * Update resolver's cache with Tapi context modelObject.
+ *
+ * @param resolver TapiResolver
+ * @param context Context ModelObject which has all data nodes of Tapi DataTree in Dcs store
+ */
@VisibleForTesting
- protected void updateCache(DefaultTapiResolver resolver, ModelObject context) {
+ protected void updateCache(DefaultTapiResolver resolver, DefaultContext context) {
updateNodes(resolver, getNodes(context));
updateNeps(resolver, getNeps(context));
}
- private ModelObject readContextModelObject() {
+ /**
+ * Get Tapi context modelObject from Dcs.
+ *
+ * @return Tapi context modelObject in Dcs store
+ */
+ // FIXME update this method using TapiContextHandler
+ private DefaultContext readContextModelObject() {
// read DataNode from DCS
ModelObjectId mid = ModelObjectId.builder().addChild(DefaultContext.class).build();
DataNode node = dcs.readNode(getResourceId(mid), Filter.builder().build());
@@ -82,15 +101,20 @@
ResourceData data = DefaultResourceData.builder().addDataNode(node)
.resourceId(ResourceId.builder().build()).build();
ModelObjectData modelData = modelConverter.createModel(data);
- ModelObject context = modelData.modelObjects().get(0);
+ DefaultContext context = (DefaultContext) modelData.modelObjects().get(0);
return context;
}
- private List<TapiNodeRef> getNodes(ModelObject context) {
- Augmentable augmentedContext = (Augmentable) context;
+ /**
+ * Extract Tapi Nodes from context modelObject and convert them to NodeRefs.
+ *
+ * @param context
+ * @return List of NodeRef
+ */
+ private List<TapiNodeRef> getNodes(DefaultContext context) {
DefaultAugmentedTapiCommonContext topologyContext
- = augmentedContext.augmentation(DefaultAugmentedTapiCommonContext.class);
+ = context.augmentation(DefaultAugmentedTapiCommonContext.class);
Topology topology = topologyContext.topology().get(0);
if (topology.node() == null) {
@@ -98,19 +122,27 @@
}
return topology.node().stream()
.map(node -> {
- String deviceId = node.name().stream()
- .filter(kv -> kv.valueName().equals(DEVICE_ID))
- .findFirst().map(Name::value).get();
- return DcsBasedTapiNodeRef.create(topology, node)
- .setDeviceId(DeviceId.deviceId(deviceId));
+ DcsBasedTapiNodeRef nodeRef = DcsBasedTapiNodeRef.create(topology, node);
+ if (node.name() != null) {
+ String deviceId = node.name().stream()
+ .filter(kv -> kv.valueName().equals(DEVICE_ID))
+ .findFirst().map(Name::value).get();
+ nodeRef.setDeviceId(DeviceId.deviceId(deviceId));
+ }
+ return nodeRef;
})
.collect(Collectors.toList());
}
- private List<TapiNepRef> getNeps(ModelObject context) {
- Augmentable augmentedContext = (Augmentable) context;
+ /**
+ * Extract Tapi Neps from context modelObject and convert them to NepRefs.
+ *
+ * @param context
+ * @return List of TapiNepRef
+ */
+ private List<TapiNepRef> getNeps(DefaultContext context) {
DefaultAugmentedTapiCommonContext topologyContext
- = augmentedContext.augmentation(DefaultAugmentedTapiCommonContext.class);
+ = context.augmentation(DefaultAugmentedTapiCommonContext.class);
Topology topology = topologyContext.topology().get(0);
if (topology.node() == null) {
@@ -118,22 +150,41 @@
}
List<TapiNepRef> ret = topology.node().stream()
.flatMap(node -> {
- if (node.ownedNodeEdgePoint() == null) {
- return null;
- }
- return node.ownedNodeEdgePoint().stream()
+ if (node.ownedNodeEdgePoint() == null) {
+ return null;
+ }
+ return node.ownedNodeEdgePoint().stream()
.map(nep -> {
- String onosConnectPoint = nep.name().stream()
- .filter(kv -> kv.valueName().equals(ONOS_CP))
- .findFirst().map(Name::value).get();
- TapiNepRef nepRef = DcsBasedTapiNepRef.create(topology, node, nep)
- .setConnectPoint(ConnectPoint.fromString(onosConnectPoint));
+ TapiNepRef nepRef = DcsBasedTapiNepRef.create(topology, node, nep);
+ if (nep.name() != null) {
+ Map<String, String> kvs = new HashMap<>();
+ nep.name().forEach(kv -> kvs.put(kv.valueName(), kv.value()));
+
+ String onosConnectPoint = kvs.getOrDefault(ONOS_CP, null);
+ String portType = kvs.getOrDefault(ODTN_PORT_TYPE, null);
+ String connectionId = kvs.getOrDefault(CONNECTION_ID, null);
+ nepRef.setConnectPoint(ConnectPoint.fromString(onosConnectPoint))
+ .setPortType(portType)
+ .setConnectionId(connectionId);
+ }
if (nep.mappedServiceInterfacePoint() != null) {
nep.mappedServiceInterfacePoint().stream()
.forEach(sip -> {
nepRef.setSipId(sip.serviceInterfacePointId().toString());
});
}
+
+ DefaultAugmentedTapiTopologyOwnedNodeEdgePoint augmentNep =
+ nep.augmentation(DefaultAugmentedTapiTopologyOwnedNodeEdgePoint.class);
+ try {
+ if (augmentNep.connectionEndPoint() != null) {
+ List<String> cepIds = augmentNep.connectionEndPoint().stream()
+ .map(cep -> cep.uuid().toString()).collect(Collectors.toList());
+ nepRef.setCepIds(cepIds);
+ }
+ } catch (NullPointerException e) {
+ log.warn("Augmented ownedNodeEdgePoint is not found.");
+ }
return nepRef;
});
}
@@ -141,16 +192,26 @@
return ret;
}
+ /**
+ * Update resolver's NodeRef list.
+ *
+ * @param resolver TapiResolver
+ * @param nodes List of NodeRef for update
+ */
private void updateNodes(DefaultTapiResolver resolver, List<TapiNodeRef> nodes) {
resolver.addNodeRefList(nodes);
}
+ /**
+ * Update resolver's NepRef list.
+ *
+ * @param resolver TapiResolver
+ * @param neps List of NepRef for update
+ */
private void updateNeps(DefaultTapiResolver resolver, List<TapiNepRef> neps) {
resolver.addNepRefList(neps);
}
-
-
private ResourceId getResourceId(ModelObjectId modelId) {
ModelObjectData data = DefaultModelObjectData.builder()
.identifier(modelId)
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiTopologyManager.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiTopologyManager.java
index 1ab7f12..b28c769 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiTopologyManager.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DcsBasedTapiTopologyManager.java
@@ -36,14 +36,17 @@
import org.onosproject.net.Link;
import org.onosproject.net.Port;
-import org.onosproject.odtn.utils.tapi.TapiLinkBuilder;
+import org.onosproject.odtn.TapiResolver;
+import org.onosproject.odtn.TapiTopologyManager;
+import org.onosproject.odtn.utils.tapi.TapiLinkHandler;
+import org.onosproject.odtn.utils.tapi.TapiCepHandler;
import org.onosproject.odtn.utils.tapi.TapiNepRef;
import org.onosproject.odtn.utils.tapi.TapiNodeRef;
-import org.onosproject.odtn.utils.tapi.TapiContextBuilder;
-import org.onosproject.odtn.utils.tapi.TapiNepBuilder;
-import org.onosproject.odtn.utils.tapi.TapiNodeBuilder;
-import org.onosproject.odtn.utils.tapi.TapiSipBuilder;
-import org.onosproject.odtn.utils.tapi.TapiTopologyBuilder;
+import org.onosproject.odtn.utils.tapi.TapiContextHandler;
+import org.onosproject.odtn.utils.tapi.TapiNepHandler;
+import org.onosproject.odtn.utils.tapi.TapiNodeHandler;
+import org.onosproject.odtn.utils.tapi.TapiSipHandler;
+import org.onosproject.odtn.utils.tapi.TapiTopologyHandler;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
@@ -55,7 +58,7 @@
import static org.slf4j.LoggerFactory.getLogger;
/**
- * OSGi Component for ODTN Tapi manager application.
+ * OSGi Component for ODTN TAPI topology manager application.
*/
@Component(immediate = true)
@Service
@@ -72,8 +75,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TapiResolver tapiResolver;
- private DefaultContext context = new DefaultContext();
- private DefaultTopology topology = new DefaultTopology();
+ private DefaultContext context;
+ private DefaultTopology topology;
@Activate
public void activate() {
@@ -95,9 +98,9 @@
if (tapiResolver.hasNodeRef(deviceId)) {
return;
}
- TapiNodeBuilder.builder()
+ TapiNodeHandler.create()
.setTopologyUuid(topology.uuid())
- .setDeviceId(deviceId).build();
+ .setDeviceId(deviceId).add();
}
@Override
@@ -115,10 +118,10 @@
TapiNepRef srcNepRef = tapiResolver.getNepRef(link.src());
TapiNepRef dstNepRef = tapiResolver.getNepRef(link.dst());
- TapiLinkBuilder.builder()
+ TapiLinkHandler.create()
.setTopologyUuid(topology.uuid())
.addNep(srcNepRef)
- .addNep(dstNepRef).build();
+ .addNep(dstNepRef).add();
}
@Override
@@ -139,19 +142,27 @@
String nodeId = nodeRef.getNodeId();
// nep
- TapiNepBuilder nepBuilder = TapiNepBuilder.builder()
- .setConnectPoint(cp)
+ TapiNepHandler nepBuilder = TapiNepHandler.create()
+ .setPort(port)
.setTopologyUuid(topology.uuid())
.setNodeUuid(Uuid.fromString(nodeId));
- // sip
- if (TapiSipBuilder.isSip(cp)) {
+ // cep
+ TapiCepHandler cepBuilder = TapiCepHandler.create()
+ .setTopologyUuid(topology.uuid())
+ .setNodeUuid(Uuid.fromString(nodeId))
+ .setNepUuid(nepBuilder.getId())
+ .setParentNep();
+ nepBuilder.addCep(cepBuilder.getModelObject());
- TapiSipBuilder sipBuilder = TapiSipBuilder.builder().setConnectPoint(cp);
- nepBuilder.addSip(sipBuilder.getUuid());
- sipBuilder.build();
+ if (TapiSipHandler.isSip(port)) {
+ TapiSipHandler sipBuilder = TapiSipHandler.create().setPort(port);
+ nepBuilder.addSip(sipBuilder.getId());
+
+ sipBuilder.add();
}
- nepBuilder.build();
+
+ nepBuilder.add();
}
@Override
@@ -159,16 +170,30 @@
log.info("Remove port: {}", port);
}
+ /**
+ * Add Tapi Context to Dcs store.
+ */
private void initDcsTapiContext() {
- TapiContextBuilder.builder(context).build();
+ TapiContextHandler contextHandler = TapiContextHandler.create();
+ context = contextHandler.getModelObject();
+ contextHandler.add();
}
+ /**
+ * Add Tapi Topology to Dcs store.
+ *
+ * Assumed there is only one topology for ODTN Phase 1.0
+ */
private void initDcsTapiTopology() {
- TapiTopologyBuilder.builder(topology).build();
+ TapiTopologyHandler topologyHandler = TapiTopologyHandler.create();
+ topology = topologyHandler.getModelObject();
+ topologyHandler.add();
}
- // FIXME: move DCS-related methods to DCS
-
+ /**
+ * Setup Dcs configuration tree root node.
+ */
+ // FIXME Dcs seems to setup root node by itself when activatation, this might not needed
private void initDcsIfRootNotExist() {
log.info("read root:");
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiPathComputer.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiPathComputer.java
new file mode 100644
index 0000000..f7688cc
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiPathComputer.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.onosproject.net.DeviceId;
+import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
+import org.onosproject.odtn.TapiResolver;
+import org.onosproject.odtn.utils.tapi.TapiCepRef;
+import org.onosproject.odtn.utils.tapi.TapiConnection;
+import org.onosproject.odtn.utils.tapi.TapiNepPair;
+import org.onosproject.odtn.utils.tapi.TapiNepRef;
+
+import static org.onlab.osgi.DefaultServiceDirectory.getService;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE;
+import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DCS-dependent Tapi path computation engine implementation.
+ */
+public class DefaultTapiPathComputer implements TapiPathComputer {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ protected TapiResolver resolver;
+
+ public static DefaultTapiPathComputer create() {
+ DefaultTapiPathComputer self = new DefaultTapiPathComputer();
+ self.resolver = getService(TapiResolver.class);
+ return self;
+ }
+
+ @Override
+ public TapiConnection pathCompute(TapiNepPair neps) {
+ log.info("Path compute with: {}", neps);
+ return pathComputeDetail(neps);
+ }
+
+ /**
+ * Compute and decide multi-hop route/path from e2e intent.
+ * <p>
+ * FIXME this can work only for Phase1.0, we need some features to:
+ * - define Route and select media channel
+ * - with pre-defined topology and forwarding constraint of each devices or domains
+ * - get all ConnectionEndPoint in the defined route and return them
+ * as list of Cep pair for each connection to be created
+ */
+ private TapiConnection pathComputeDetail(TapiNepPair neps) {
+ return mockPathCompute(neps);
+ }
+
+
+ /**
+ * Mock to create path computation result.
+ *
+ * neps.left connection neps.right
+ * ■----------------------------------------------------■
+ * \ /
+ * \ /
+ * \ leftLowerConnection / rightLowerConnection
+ * \ /
+ * \ /
+ * ■ ■
+ * leftLineNep rightLineNep
+ */
+ private TapiConnection mockPathCompute(TapiNepPair neps) {
+ TapiNepRef leftLineNep = mockGetTransponderLinePort(neps.left());
+ TapiNepRef rightLineNep = mockGetTransponderLinePort(neps.right());
+
+ TapiConnection leftLowerConnection = TapiConnection.create(
+ TapiCepRef.create(neps.left(), neps.left().getCepIds().get(0)),
+ TapiCepRef.create(leftLineNep, leftLineNep.getCepIds().get(0))
+ );
+
+ TapiConnection rightLowerConnection = TapiConnection.create(
+ TapiCepRef.create(neps.right(), neps.right().getCepIds().get(0)),
+ TapiCepRef.create(rightLineNep, rightLineNep.getCepIds().get(0))
+ );
+
+ TapiConnection connection = TapiConnection.create(
+ TapiCepRef.create(neps.left(), neps.left().getCepIds().get(0)),
+ TapiCepRef.create(neps.right(), neps.right().getCepIds().get(0))
+ );
+ connection.addLowerConnection(leftLowerConnection)
+ .addLowerConnection(rightLowerConnection);
+
+ return connection;
+ }
+
+ /**
+ * Mock to select line port from client port.
+ */
+ private TapiNepRef mockGetTransponderLinePort(TapiNepRef cliNepRef) {
+ DeviceId deviceId = cliNepRef.getConnectPoint().deviceId();
+ Map<String, String> filter = new HashMap<>();
+ filter.put(DEVICE_ID, deviceId.toString());
+ filter.put(ODTN_PORT_TYPE, OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value());
+ filter.put(CONNECTION_ID, cliNepRef.getConnectionId());
+ return resolver.getNepRefs(filter).stream().findAny().get();
+ }
+
+}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiResolver.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiResolver.java
index f5a9bc6..f309d6d 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiResolver.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/DefaultTapiResolver.java
@@ -18,21 +18,27 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.ElementId;
+import org.onosproject.odtn.TapiResolver;
import org.onosproject.odtn.utils.tapi.TapiNepRef;
import org.onosproject.odtn.utils.tapi.TapiNodeRef;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
-
+/**
+ * OSGi Component for ODTN TAPI resolver application.
+ */
@Component(immediate = true)
@Service
public class DefaultTapiResolver implements TapiResolver {
@@ -47,7 +53,7 @@
/**
* When source (e.g. DCS) is updated, set true
* When cache update completed successfully, set false
- *
+ * <p>
* This flag takes effect when cache update failed with exception,
* this remains to be true so the cache update process conducts again
*/
@@ -56,7 +62,7 @@
/**
* When source (e.g. DCS) is updated, set true
* When cache update started, set false
- *
+ * <p>
* This flag takes effect when source updated during cache updating
* this forces cache update again at the next request
*/
@@ -95,12 +101,27 @@
}
@Override
+ public TapiNodeRef getNodeRef(TapiNodeRef nodeRef) throws NoSuchElementException {
+ updateCache();
+ TapiNodeRef ret = null;
+ try {
+ ret = tapiNodeRefList.stream()
+ .filter(nodeRef::equals)
+ .findFirst().get();
+ } catch (NoSuchElementException e) {
+ log.error("Node not found of {}", nodeRef);
+ throw e;
+ }
+ return ret;
+ }
+
+ @Override
public TapiNodeRef getNodeRef(ElementId deviceId) throws NoSuchElementException {
updateCache();
TapiNodeRef ret = null;
try {
ret = tapiNodeRefList.stream()
- .filter(node -> node.getDeviceId().equals(deviceId))
+ .filter(node -> node.getDeviceId() != null && node.getDeviceId().equals(deviceId))
.findFirst().get();
} catch (NoSuchElementException e) {
log.error("Node not found associated with {}", deviceId);
@@ -116,12 +137,37 @@
}
@Override
+ public List<TapiNodeRef> getNodeRefs(Map<String, String> filter) {
+ updateCache();
+ Stream<TapiNodeRef> filterStream = tapiNodeRefList.stream();
+ for (String key : filter.keySet()) {
+ filterStream = filterStream.filter(nodeRef -> nodeRef.is(key, filter.get(key)));
+ }
+ return filterStream.collect(Collectors.toList());
+ }
+
+ @Override
+ public TapiNepRef getNepRef(TapiNepRef nepRef) throws NoSuchElementException {
+ updateCache();
+ TapiNepRef ret = null;
+ try {
+ ret = tapiNepRefList.stream()
+ .filter(nepRef::equals)
+ .findFirst().get();
+ } catch (NoSuchElementException e) {
+ log.error("Nep not found of {}", nepRef);
+ throw e;
+ }
+ return ret;
+ }
+
+ @Override
public TapiNepRef getNepRef(ConnectPoint cp) throws NoSuchElementException {
updateCache();
TapiNepRef ret = null;
try {
ret = tapiNepRefList.stream()
- .filter(nep -> nep.getConnectPoint().equals(cp))
+ .filter(nep -> nep.getConnectPoint() != null && nep.getConnectPoint().equals(cp))
.findFirst().get();
} catch (NoSuchElementException e) {
log.error("Nep not found associated with {}", cp);
@@ -136,7 +182,7 @@
TapiNepRef ret = null;
try {
ret = tapiNepRefList.stream()
- .filter(nep -> nep.getSipId().equals(sipId))
+ .filter(nep -> nep.getSipId() != null && nep.getSipId().equals(sipId))
.findFirst().get();
} catch (NoSuchElementException e) {
log.error("Nep not found associated with {}", sipId);
@@ -152,6 +198,16 @@
}
@Override
+ public List<TapiNepRef> getNepRefs(Map<String, String> filter) {
+ updateCache();
+ Stream<TapiNepRef> filterStream = tapiNepRefList.stream();
+ for (String key : filter.keySet()) {
+ filterStream = filterStream.filter(nepRef -> nepRef.is(key, filter.get(key)));
+ }
+ return filterStream.collect(Collectors.toList());
+ }
+
+ @Override
public void makeDirty() {
sourceUpdated = true;
isDirty = true;
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiConnectionManager.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiConnectionManager.java
new file mode 100644
index 0000000..baffde9
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiConnectionManager.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.internal;
+
+import org.onosproject.odtn.utils.tapi.TapiNepPair;
+import org.onosproject.odtn.utils.tapi.TapiConnectionHandler;
+
+/**
+ * ODTN Tapi connectivity-service:connection manager.
+ */
+public interface TapiConnectionManager {
+
+ /**
+ * Queue Tapi connection object to add to DCS.
+ * If target connection has lower-connections, they are also queued recursively
+ * using other TapiConnectionManager instance.
+ * <p>
+ * Operation will not be conducted until apply method called.
+ *
+ * @param neps Both NodeEdgePoints of Nodes(devices or domains) in the calculated route.
+ * @return connectionHandler of connection to be created
+ */
+ TapiConnectionHandler createConnection(TapiNepPair neps);
+
+ /**
+ * Queue Tapi connection object to remove from DCS
+ * If target connection has lower-connections, they are also queued recursively
+ * using other TapiConnectionManager instance.
+ * <p>
+ * Operation will not be conducted until apply method called.
+ *
+ * @param connectionHandler handler of TAPI connection object to be deleted
+ */
+ void deleteConnection(TapiConnectionHandler connectionHandler);
+
+ /**
+ * Apply add/remove operation for queued connection instances.
+ * If target connection has lower-connections, they are also operated recursively
+ * by other TapiConnectionManager instance.
+ */
+ void apply();
+
+}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiDataProducer.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiDataProducer.java
index 8d0c2d5..0096fa3 100644
--- a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiDataProducer.java
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiDataProducer.java
@@ -25,6 +25,7 @@
/**
* Update TapiResolver cache with latest modelObject in DCS.
+ *
* @param resolver update target itself
*/
void updateCacheRequest(DefaultTapiResolver resolver);
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiPathComputer.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiPathComputer.java
new file mode 100644
index 0000000..3951f57
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/internal/TapiPathComputer.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.odtn.internal;
+
+import org.onosproject.odtn.utils.tapi.TapiConnection;
+import org.onosproject.odtn.utils.tapi.TapiNepPair;
+
+/**
+ * ODTN Tapi path computation service.
+ */
+public interface TapiPathComputer {
+
+ /**
+ * Compute and decide multi-hop route/path from e2e intent.
+ *
+ * @param neps Both NodeEdgePoints associated with ServiceInterfacePoint of NBI request
+ * @return List of both CEPs of devices or domains in the calculated route
+ */
+ TapiConnection pathCompute(TapiNepPair neps);
+}
diff --git a/apps/odtn/service/src/main/java/org/onosproject/odtn/package-info.java b/apps/odtn/service/src/main/java/org/onosproject/odtn/package-info.java
new file mode 100644
index 0000000..8c0e6a0
--- /dev/null
+++ b/apps/odtn/service/src/main/java/org/onosproject/odtn/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Package to place ODTN interfaces.
+ */
+package org.onosproject.odtn;
diff --git a/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducerTest.java b/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducerTest.java
index b259235..e616b21 100644
--- a/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducerTest.java
+++ b/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DcsBasedTapiDataProducerTest.java
@@ -27,12 +27,12 @@
import org.onosproject.net.PortNumber;
import org.onosproject.odtn.utils.tapi.DcsBasedTapiNepRef;
import org.onosproject.odtn.utils.tapi.DcsBasedTapiNodeRef;
-import org.onosproject.odtn.utils.tapi.TapiNepBuilder;
+import org.onosproject.odtn.utils.tapi.TapiNepHandler;
import org.onosproject.odtn.utils.tapi.TapiNepRef;
-import org.onosproject.odtn.utils.tapi.TapiNodeBuilder;
+import org.onosproject.odtn.utils.tapi.TapiNodeHandler;
import org.onosproject.odtn.utils.tapi.TapiNodeRef;
-import org.onosproject.odtn.utils.tapi.TapiSipBuilder;
-import org.onosproject.odtn.utils.tapi.TapiTopologyBuilder;
+import org.onosproject.odtn.utils.tapi.TapiSipHandler;
+import org.onosproject.odtn.utils.tapi.TapiTopologyHandler;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.tapicontext.DefaultServiceInterfacePoint;
import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.context.DefaultAugmentedTapiCommonContext;
@@ -73,49 +73,49 @@
context = new DefaultContext();
- topology = TapiTopologyBuilder.builder(new DefaultTopology()).getModelObject();
+ topology = TapiTopologyHandler.create().getModelObject();
DefaultAugmentedTapiCommonContext topologyContext = new DefaultAugmentedTapiCommonContext();
topologyContext.addToTopology(topology);
Augmentable augmentableContext = context;
augmentableContext.addAugmentation(topologyContext);
- node1 = TapiNodeBuilder.builder()
+ node1 = TapiNodeHandler.create()
.setTopologyUuid(topology.uuid())
.setDeviceId(did1)
.getModelObject();
- node2 = TapiNodeBuilder.builder()
+ node2 = TapiNodeHandler.create()
.setTopologyUuid(topology.uuid())
.setDeviceId(did2)
.getModelObject();
- sip11 = TapiSipBuilder.builder()
+ sip11 = TapiSipHandler.create()
.setConnectPoint(cp11).getModelObject();
- sip21 = TapiSipBuilder.builder()
+ sip21 = TapiSipHandler.create()
.setConnectPoint(cp21).getModelObject();
- nep11 = TapiNepBuilder.builder()
+ nep11 = TapiNepHandler.create()
.setTopologyUuid(topology.uuid())
.setNodeUuid(node1.uuid())
.setConnectPoint(cp11)
.addSip(sip11.uuid())
.getModelObject();
- nep12 = TapiNepBuilder.builder()
+ nep12 = TapiNepHandler.create()
.setTopologyUuid(topology.uuid())
.setNodeUuid(node1.uuid())
.setConnectPoint(cp12)
.getModelObject();
- nep21 = TapiNepBuilder.builder()
+ nep21 = TapiNepHandler.create()
.setTopologyUuid(topology.uuid())
.setNodeUuid(node2.uuid())
.setConnectPoint(cp21)
.addSip(sip21.uuid())
.getModelObject();
- nep22 = TapiNepBuilder.builder()
+ nep22 = TapiNepHandler.create()
.setTopologyUuid(topology.uuid())
.setNodeUuid(node2.uuid())
.setConnectPoint(cp22)
diff --git a/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DefaultTapiResolverTest.java b/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DefaultTapiResolverTest.java
index 9696f50..5fcad14 100644
--- a/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DefaultTapiResolverTest.java
+++ b/apps/odtn/service/src/test/java/org/onosproject/odtn/internal/DefaultTapiResolverTest.java
@@ -16,6 +16,10 @@
package org.onosproject.odtn.internal;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import org.easymock.EasyMock;
import org.junit.Before;
@@ -23,19 +27,22 @@
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
+import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
import org.onosproject.odtn.utils.tapi.TapiNepRef;
import org.onosproject.odtn.utils.tapi.TapiNodeRef;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE;
public class DefaultTapiResolverTest {
private DefaultTapiResolver tapiResolver;
- private TapiNodeRef nodeRef;
- private TapiNepRef nepRef;
+ private TapiNodeRef nodeRef, nodeRefNullAttr;
+ private TapiNepRef nepRef, nepRefNullAttr;
private DeviceId deviceId;
private ConnectPoint cp;
private String sipId;
@@ -44,6 +51,7 @@
private Integer dummyPort;
private ConnectPoint dummyCp;
private String dummySipId;
+ private String portType;
private TapiDataProducer mockTapiDataProducer;
@@ -56,11 +64,19 @@
"59e2ac46-3975-44b4-b84f-8fab28222a39",
"6638e8e6-ac17-40d9-86e4-7c1febab6f1a",
"cd673055-e2b2-4f67-88c8-adfae96385bc");
+ nodeRefNullAttr = TapiNodeRef.create(
+ "59e2ac46-3975-44b4-b84f-8fab28222a39",
+ "6638e8e6-ac17-40d9-86e4-7c1febab6f1a");
+ nepRefNullAttr = TapiNepRef.create(
+ "69e2ac46-3975-44b4-b84f-8fab28222a39",
+ "7638e8e6-ac17-40d9-86e4-7c1febab6f1a",
+ "dd673055-e2b2-4f67-88c8-adfae96385bc");
deviceId = DeviceId.deviceId("netconf:172.24.3.5:11011");
cp = new ConnectPoint(deviceId, PortNumber.portNumber("42"));
sipId = "01c39723-7c0d-4754-8d64-fd9ff412404c";
+ portType = OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value();
nodeRef.setDeviceId(deviceId);
- nepRef.setConnectPoint(cp).setSipId(sipId);
+ nepRef.setConnectPoint(cp).setSipId(sipId).setPortType(portType);
dummyDeviceId = DeviceId.deviceId("dummy");
dummyPort = 4;
@@ -83,13 +99,34 @@
}
@Test
- public void testGetNepRefWithConnectPoint() {
+ public void testGetNepRefByConnectPoint() {
tapiResolver.addNepRef(nepRef);
assertThat(nepRef, is(tapiResolver.getNepRef(cp)));
}
@Test
- public void testGetNepRefWithSipId() {
+ public void testGetNepRefBySipId() {
+ tapiResolver.addNepRef(nepRef);
+ assertThat(nepRef, is(tapiResolver.getNepRef(sipId)));
+ }
+
+ @Test
+ public void testGetNodeRefWithNullAttrObj() {
+ tapiResolver.addNodeRef(nodeRefNullAttr);
+ tapiResolver.addNodeRef(nodeRef);
+ assertThat(nodeRef, is(tapiResolver.getNodeRef(deviceId)));
+ }
+
+ @Test
+ public void testGetNepRefByConnectPointWithNullAttrObj() {
+ tapiResolver.addNepRef(nepRefNullAttr);
+ tapiResolver.addNepRef(nepRef);
+ assertThat(nepRef, is(tapiResolver.getNepRef(cp)));
+ }
+
+ @Test
+ public void testGetNepRefBySipIdWithNullAttrObj() {
+ tapiResolver.addNepRef(nepRefNullAttr);
tapiResolver.addNepRef(nepRef);
assertThat(nepRef, is(tapiResolver.getNepRef(sipId)));
}
@@ -106,25 +143,53 @@
@Test(expected = NoSuchElementException.class)
public void testGetNepRefWithSipIdWhenEmpty() {
- tapiResolver.getNepRef(cp);
+ tapiResolver.getNepRef(sipId);
}
@Test(expected = NoSuchElementException.class)
public void testGetNodeRefNotExist() {
+ tapiResolver.addNodeRef(nodeRefNullAttr);
tapiResolver.addNodeRef(nodeRef);
tapiResolver.getNodeRef(dummyDeviceId);
}
@Test(expected = NoSuchElementException.class)
public void testGetNepRefWithConnectPointNotExist() {
+ tapiResolver.addNepRef(nepRefNullAttr);
tapiResolver.addNepRef(nepRef);
tapiResolver.getNepRef(dummyCp);
}
@Test(expected = NoSuchElementException.class)
public void testGetNepRefWithSipIdNotExist() {
+ tapiResolver.addNepRef(nepRefNullAttr);
tapiResolver.addNepRef(nepRef);
tapiResolver.getNepRef(dummySipId);
}
+ @Test
+ public void testGetNodeRefsFiltered() {
+ tapiResolver.addNodeRef(nodeRefNullAttr);
+ tapiResolver.addNodeRef(nodeRef);
+ List<TapiNodeRef> exp = Arrays.asList(nodeRef);
+ Map<String, String> filter = new HashMap<>();
+ filter.put(DEVICE_ID, deviceId.toString());
+
+ assertThat(tapiResolver.getNodeRefs(filter), is(exp));
+ }
+
+ @Test
+ public void testGetNepRefsFiltered() {
+ tapiResolver.addNepRef(nepRefNullAttr);
+ tapiResolver.addNepRef(nepRef);
+ List<TapiNepRef> exp = Arrays.asList(nepRef);
+ Map<String, String> filter = new HashMap<>();
+
+ filter.put(DEVICE_ID, deviceId.toString());
+ assertThat(tapiResolver.getNepRefs(filter), is(exp));
+
+ filter.put(ODTN_PORT_TYPE, portType);
+ assertThat(tapiResolver.getNepRefs(filter), is(exp));
+ }
+
}
\ No newline at end of file
diff --git a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscovery.java b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscovery.java
index 347a0c8..4ebe973 100644
--- a/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscovery.java
+++ b/drivers/odtn-driver/src/main/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscovery.java
@@ -148,14 +148,12 @@
//log.warn("parent data Node: {}",
// ((SubnodeConfiguration) component).getParent().getRootNode().getName());
-
String name = component.getString("name");
checkNotNull(name);
if (!name.contains("GIGECLIENTCTP")) {
return null;
}
-
Builder builder = DefaultPortDescription.builder();
Map<String, String> props = new HashMap<>();
@@ -168,12 +166,17 @@
Matcher lineMatch = linePattern.matcher(name);
if (clientMatch.find()) {
+ String num = clientMatch.group(1);
+ Integer connection = (Integer.parseInt(num) + 1) / 2;
props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
- builder.withPortNumber(PortNumber.portNumber(Long.parseLong(clientMatch.group(1)), name));
+ props.putIfAbsent(CONNECTION_ID, "connection:" + connection.toString());
+ builder.withPortNumber(PortNumber.portNumber(Long.parseLong(num), name));
builder.type(Type.PACKET);
} else if (lineMatch.find()) {
+ String num = lineMatch.group(1);
props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
- builder.withPortNumber(PortNumber.portNumber(100 + Long.parseLong(lineMatch.group(1)), name));
+ props.putIfAbsent(CONNECTION_ID, "connection:" + num);
+ builder.withPortNumber(PortNumber.portNumber(100 + Long.parseLong(num), name));
builder.type(Type.OCH);
} else {
return null;
diff --git a/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscoveryTest.java b/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscoveryTest.java
index f86945c..e9f87a9 100644
--- a/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscoveryTest.java
+++ b/drivers/odtn-driver/src/test/java/org/onosproject/drivers/odtn/InfineraOpenConfigDeviceDiscoveryTest.java
@@ -29,7 +29,7 @@
import static org.junit.Assert.assertThat;
import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_NAME;
import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.OC_TYPE;
-import static org.onosproject.odtn.utils.tapi.TapiInstanceBuilder.ODTN_PORT_TYPE;
+import static org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE;
public class InfineraOpenConfigDeviceDiscoveryTest {