Add Tapi Context/Topology/Node/Link builders and utility class

ONOS-7679

Change-Id: I85f856b11a5e272460b38c16ca46212fb4a0a082
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
new file mode 100644
index 0000000..aa8e553
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNepRef.java
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+public class DcsBasedTapiNepRef extends TapiNepRef {
+
+    public DcsBasedTapiNepRef(Uuid topologyId, Uuid nodeId, Uuid nepId) {
+        super(topologyId.toString(), nodeId.toString(), nepId.toString());
+    }
+
+}
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
new file mode 100644
index 0000000..5e3c79b
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/DcsBasedTapiNodeRef.java
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+public class DcsBasedTapiNodeRef extends TapiNodeRef {
+
+    public DcsBasedTapiNodeRef(Uuid topologyId, Uuid nodeId) {
+        super(topologyId.toString(), nodeId.toString());
+    }
+}
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
new file mode 100644
index 0000000..2d24dc4
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiContextBuilder.java
@@ -0,0 +1,55 @@
+/*
+ * 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.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+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 ModelObjectData build() {
+        ModelObjectId objId = ModelObjectId.builder().build();
+        return getModelObjectData(context, objId);
+    }
+
+    @Override
+    public ModelObject getModelObject() {
+        return context;
+    }
+
+    @Override
+    public Uuid getUuid() {
+        return null;
+    }
+}
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
new file mode 100644
index 0000000..834c927
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiGlobalClassUtil.java
@@ -0,0 +1,111 @@
+/*
+ * 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.globalclass.DefaultName;
+import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.globalclass.Name;
+import org.onosproject.yang.model.ModelObject;
+
+import java.lang.reflect.InvocationTargetException;
+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> tapi-common@2018-03-07.yang
+ * grouping global-class {
+ *   leaf uuid {
+ *     type uuid;
+ *   }
+ *   list name {
+ *     key 'value-name';
+ *     uses name-and-value;
+ *   }
+ * }
+ *
+ * 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 TapiGlobalClassUtil {
+
+    private static final Logger log = getLogger(TapiGlobalClassUtil.class);
+
+    private TapiGlobalClassUtil() {
+    }
+
+    /**
+     * Generate and set Uuid for the ModelObject.
+     * @param obj ModelObject
+     * @param <T> type of ModelObject
+     * @return generated uuid
+     */
+    public static <T extends ModelObject> Uuid setUuid(T obj) {
+        Uuid uuid = Uuid.of(UUID.randomUUID().toString());
+
+        @SuppressWarnings("unchecked")
+        Class<T> cls = (Class<T>) obj.getClass();
+        try {
+            Method method = cls.getMethod("uuid", Uuid.class);
+            method.invoke(obj, uuid);
+        } 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
+     */
+    public static <T extends ModelObject> void setNameList(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/TapiInstanceBuilder.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiInstanceBuilder.java
new file mode 100644
index 0000000..ecb07f1
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiInstanceBuilder.java
@@ -0,0 +1,59 @@
+/*
+ * 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.DefaultModelObjectData;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * 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";
+
+    /**
+     * Generate DCS modelObjectData.
+     * @return ModelObjectData to be built
+     */
+    public abstract ModelObjectData build();
+
+    /**
+     * Get modelObject instance.
+     * @return ModelObject of build target
+     */
+    public abstract ModelObject getModelObject();
+
+    /**
+     * Get modelObject uuid.
+     * @return Uuid of build target
+     */
+    public abstract Uuid getUuid();
+
+
+    ModelObjectData getModelObjectData(ModelObject obj, ModelObjectId objId) {
+        return DefaultModelObjectData.builder()
+                .addModelObject(obj)
+                .identifier(objId)
+                .build();
+    }
+}
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/TapiLinkBuilder.java
new file mode 100644
index 0000000..93fbe5b
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiLinkBuilder.java
@@ -0,0 +1,83 @@
+/*
+ * 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.tapitopology.rev20180307.tapitopology.link.DefaultNodeEdgePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultLink;
+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.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
+
+/**
+ * Utility builder class for TAPI link creation with DCS.
+ */
+public final class TapiLinkBuilder extends TapiInstanceBuilder {
+
+    private Uuid topologyUuid;
+    private DefaultLink link = new DefaultLink();
+
+    private TapiLinkBuilder() {
+        setUuid(link);
+    }
+
+    public static TapiLinkBuilder builder() {
+        return new TapiLinkBuilder();
+    }
+
+    public TapiLinkBuilder setTopologyUuid(Uuid topologyUuid) {
+        this.topologyUuid = topologyUuid;
+        return this;
+    }
+
+    public TapiLinkBuilder setNep(TapiNepRef nepRef) {
+        DefaultNodeEdgePoint nep = new DefaultNodeEdgePoint();
+        nep.topologyId(nepRef.getTopologyId());
+        nep.nodeId(nepRef.getNodeId());
+        nep.ownedNodeEdgePointId(nepRef.getNepId());
+        link.addToNodeEdgePoint(nep);
+        return this;
+    }
+
+    @Override
+    public ModelObjectData build() {
+
+        TopologyKeys topologyKey = new TopologyKeys();
+        topologyKey.uuid(topologyUuid);
+        ModelObjectId objId = ModelObjectId.builder()
+                .addChild(DefaultContext.class)
+                .addChild(DefaultTopology.class, topologyKey)
+                .build();
+        return getModelObjectData(link, objId);
+    }
+
+    @Override
+    public ModelObject getModelObject() {
+        return link;
+    }
+
+    @Override
+    public Uuid getUuid() {
+        return link.uuid();
+    }
+
+}
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
new file mode 100644
index 0000000..3524d63
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepBuilder.java
@@ -0,0 +1,118 @@
+/*
+ * 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 static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setNameList;
+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.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+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 setPort(Port port) {
+        cp = new ConnectPoint(port.element().id(), port.number());
+        kvs.put(ONOS_CP, cp.toString());
+        return this;
+    }
+
+    public TapiNepBuilder setConnectPoint(ConnectPoint cp) {
+        kvs.put(ONOS_CP, cp.toString());
+        return this;
+    }
+
+    public TapiNepBuilder setSip(Uuid sipUuid) {
+        DefaultMappedServiceInterfacePoint mappedSip = new DefaultMappedServiceInterfacePoint();
+        mappedSip.serviceInterfacePointId(sipUuid);
+        nep.addToMappedServiceInterfacePoint(mappedSip);
+        return this;
+    }
+
+    public ConnectPoint getConnectPoint() {
+        return cp;
+    }
+
+    @Override
+    public ModelObject getModelObject() {
+        return nep;
+    }
+
+    @Override
+    public Uuid getUuid() {
+        return nep.uuid();
+    }
+
+    @Override
+    public ModelObjectData build() {
+        setNameList(nep, kvs);
+
+        TopologyKeys topologyKey = new TopologyKeys();
+        topologyKey.uuid(topologyUuid);
+
+        NodeKeys nodeKey = new NodeKeys();
+        nodeKey.uuid(nodeUuid);
+
+        ModelObjectId objId = ModelObjectId.builder()
+                .addChild(DefaultContext.class)
+                .addChild(DefaultTopology.class, topologyKey)
+                .addChild(DefaultNode.class, nodeKey)
+                .build();
+        return getModelObjectData(nep, objId);
+    }
+
+}
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
new file mode 100644
index 0000000..a28d53d
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNepRef.java
@@ -0,0 +1,99 @@
+/*
+ * 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.net.ConnectPoint;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Objects.equal;
+import static java.util.Objects.hash;
+
+public class TapiNepRef {
+
+    private final UUID topologyId;
+    private final UUID nodeId;
+    private final UUID nepId;
+    private UUID sipId;
+    private ConnectPoint cp;
+
+    public String getTopologyId() {
+        return topologyId.toString();
+    }
+
+    public String getNodeId() {
+        return nodeId.toString();
+    }
+
+    public String getNepId() {
+        return nepId.toString();
+    }
+
+    public String getSipId() {
+        return sipId.toString();
+    }
+
+    public ConnectPoint getConnectPoint() {
+        return cp;
+    }
+
+    public TapiNepRef setSipId(String sipId) {
+        this.sipId = UUID.fromString(sipId);
+        return this;
+    }
+
+    public TapiNepRef setConnectPoint(ConnectPoint cp) {
+        this.cp = cp;
+        return this;
+    }
+
+    public TapiNepRef(String topologyId, String nodeId, String nepId) {
+        this.topologyId = UUID.fromString(topologyId);
+        this.nodeId = UUID.fromString(nodeId);
+        this.nepId = UUID.fromString(nepId);
+    }
+
+    public String toString() {
+        return toStringHelper(getClass())
+//                .add("topologyId", topologyId)
+                .add("nodeId", nodeId)
+                .add("nepId", nepId)
+                .add("sipId", sipId)
+                .add("connectPoint", cp)
+                .toString();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof TapiNepRef)) {
+            return false;
+        }
+        TapiNepRef that = (TapiNepRef) o;
+        return equal(topologyId, that.topologyId) &&
+                equal(nodeId, that.nodeId) &&
+                equal(nepId, that.nepId);
+    }
+
+    @Override
+    public int hashCode() {
+        return hash(topologyId, nodeId, nepId);
+    }
+
+}
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/TapiNodeBuilder.java
new file mode 100644
index 0000000..868df72
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeBuilder.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.HashMap;
+import java.util.Map;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setNameList;
+import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
+
+import org.onosproject.net.DeviceId;
+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.OwnedNodeEdgePoint;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultNode;
+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.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility builder class for TAPI node creation with DCS.
+ */
+public final class TapiNodeBuilder extends TapiInstanceBuilder {
+
+    private Uuid topologyUuid;
+    private DefaultNode node = new DefaultNode();
+    private Map<String, String> kvs = new HashMap<>();
+
+    private TapiNodeBuilder() {
+        setUuid(node);
+    }
+
+    public static TapiNodeBuilder builder() {
+        return new TapiNodeBuilder();
+    }
+
+    public TapiNodeBuilder setTopologyUuid(Uuid topologyUuid) {
+        this.topologyUuid = topologyUuid;
+        return this;
+    }
+
+    public TapiNodeBuilder setNep(OwnedNodeEdgePoint nep) {
+        node.addToOwnedNodeEdgePoint(nep);
+        return this;
+    }
+
+    public TapiNodeBuilder setDeviceId(DeviceId deviceId) {
+        kvs.put(DEVICE_ID, deviceId.toString());
+        return this;
+    }
+
+    @Override
+    public ModelObject getModelObject() {
+        return node;
+    }
+
+    @Override
+    public Uuid getUuid() {
+        return node.uuid();
+    }
+
+    @Override
+    public ModelObjectData build() {
+        setNameList(node, kvs);
+
+        TopologyKeys topologyKey = new TopologyKeys();
+        topologyKey.uuid(topologyUuid);
+        ModelObjectId objId = ModelObjectId.builder()
+                .addChild(DefaultContext.class)
+                .addChild(DefaultTopology.class, topologyKey)
+                .build();
+        return getModelObjectData(node, objId);
+    }
+
+}
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
new file mode 100644
index 0000000..0fd762b
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiNodeRef.java
@@ -0,0 +1,75 @@
+/*
+ * 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.net.DeviceId;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Objects.equal;
+import static java.util.Objects.hash;
+
+public class TapiNodeRef {
+
+    private final UUID topologyId;
+    private final UUID nodeId;
+    private DeviceId deviceId;
+
+    public String getNodeId() {
+        return nodeId.toString();
+    }
+
+    public DeviceId getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(DeviceId deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public TapiNodeRef(String topologyId, String nodeId) {
+        this.topologyId = UUID.fromString(topologyId);
+        this.nodeId = UUID.fromString(nodeId);
+    }
+
+    public String toString() {
+        return toStringHelper(getClass())
+//                .add("topologyId", topologyId)
+                .add("nodeId", nodeId)
+                .add("deviceId", deviceId)
+                .toString();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof TapiNodeRef)) {
+            return false;
+        }
+        TapiNodeRef nodeRef = (TapiNodeRef) o;
+        return equal(topologyId, nodeRef.topologyId) &&
+                equal(nodeId, nodeRef.nodeId);
+    }
+
+    @Override
+    public int hashCode() {
+        return hash(topologyId, nodeId);
+    }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiResolver.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiResolver.java
new file mode 100644
index 0000000..6ec62ff
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiResolver.java
@@ -0,0 +1,136 @@
+/*
+ * 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.NoSuchElementException;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.ElementId;
+import org.slf4j.Logger;
+import static org.slf4j.LoggerFactory.getLogger;
+
+
+/**
+ * TAPI instance resolver.
+ * FIXME: This resolver should provide DCS read cache
+ */
+public class TapiResolver {
+
+    private final Logger log = getLogger(getClass());
+
+    private List<TapiNodeRef> tapiNodeRefList = new ArrayList<>();
+    private List<TapiNepRef> tapiNepRefList = new ArrayList<>();
+
+
+    /**
+     * Check existence of TAPI node associated with deviceId.
+     * @param deviceId search key
+     * @return boolean
+     */
+    public boolean hasNodeRef(ElementId deviceId) {
+        return tapiNodeRefList.stream()
+                .anyMatch(node -> node.getDeviceId().equals(deviceId));
+    }
+
+    /**
+     * Check existence of TAPI nep associated with ConnectPoint.
+     * @param cp search key
+     * @return TapiNepRef
+     */
+    public boolean hasNepRef(ConnectPoint cp) {
+        return tapiNepRefList.stream()
+                .anyMatch(nep -> nep.getConnectPoint().equals(cp));
+    }
+
+    /**
+     * Check existence of TAPI nep associated with TAPI sipId.
+     * @param sipId search key
+     * @return TapiNepRef
+     */
+    public boolean hasNepRef(String sipId) {
+        return tapiNepRefList.stream()
+                .anyMatch(nep -> nep.getSipId().equals(sipId));
+    }
+
+    /**
+     * Resolve TAPI node associated with deviceId.
+     * @param deviceId search key
+     * @return TapiNodeRef
+     */
+    public TapiNodeRef getNodeRef(ElementId deviceId) {
+        TapiNodeRef ret = null;
+        try {
+            ret = tapiNodeRefList.stream()
+                    .filter(node -> node.getDeviceId().equals(deviceId))
+                    .findFirst().get();
+        } catch (NoSuchElementException e) {
+            log.error("Node not found associated with {}", deviceId);
+            throw e;
+        }
+        return ret;
+    }
+
+    /**
+     * Resolve TAPI nep associated with ConnectPoint.
+     * @param cp search key
+     * @return TapiNepRef
+     */
+    public TapiNepRef getNepRef(ConnectPoint cp) {
+        TapiNepRef ret = null;
+        try {
+            ret = tapiNepRefList.stream()
+                    .filter(nep -> nep.getConnectPoint().equals(cp))
+                    .findFirst().get();
+        } catch (NoSuchElementException e) {
+            log.error("Nep not found associated with {}", cp);
+            throw e;
+        }
+        return ret;
+    }
+
+    /**
+     * Resolve TAPI nep associated with TAPI sipId.
+     * @param sipId search key
+     * @return TapiNepRef
+     */
+    public TapiNepRef getNepRef(String sipId) {
+        TapiNepRef ret = null;
+        try {
+            ret = tapiNepRefList.stream()
+                    .filter(nep -> nep.getSipId().equals(sipId))
+                    .findFirst().get();
+        } catch (NoSuchElementException e) {
+            log.error("Nep not found associated with {}", sipId);
+            throw e;
+        }
+        return ret;
+    }
+
+    public TapiResolver addNodeRef(TapiNodeRef nodeRef) {
+        tapiNodeRefList.add(nodeRef);
+        log.info("Nodes: {}", tapiNodeRefList);
+        return this;
+    }
+
+    public TapiResolver addNepRef(TapiNepRef nepRef) {
+        tapiNepRefList.add(nepRef);
+        log.info("Neps: {}", tapiNepRefList);
+        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
new file mode 100644
index 0000000..a12a425
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiSipBuilder.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 java.util.HashMap;
+import java.util.Map;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Port;
+
+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.setNameList;
+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.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+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 Map<String, String> kvs = new HashMap<>();
+
+    private TapiSipBuilder() {
+        setUuid(sip);
+    }
+
+    public static TapiSipBuilder builder() {
+        return new TapiSipBuilder();
+    }
+
+    /**
+     * Check this builder dealing with port for SIP or not.
+     * @param port onos port
+     * @return Is this builder for SIP or not
+     */
+    public static boolean isSip(Port port) {
+        // FIXME modify this method to appropriate way
+        ConnectPoint cp = new ConnectPoint(port.element().id(), port.number());
+        return cp.toString().contains("TRANSCEIVER");
+    }
+
+    public TapiSipBuilder 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());
+        kvs.put(ONOS_CP, cp.toString());
+        sip.addToLayerProtocolName(LayerProtocolName.of(DSR));
+        return this;
+    }
+
+    @Override
+    public ModelObjectData build() {
+        setNameList(sip, kvs);
+        ModelObjectId objId = ModelObjectId.builder()
+                .addChild(DefaultContext.class)
+                .build();
+        return getModelObjectData(sip, objId);
+    }
+
+    @Override
+    public ModelObject getModelObject() {
+        return sip;
+    }
+
+    @Override
+    public Uuid getUuid() {
+        return sip.uuid();
+    }
+}
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/TapiTopologyBuilder.java
new file mode 100644
index 0000000..82e83d7
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/TapiTopologyBuilder.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 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.context.DefaultAugmentedTapiCommonContext;
+import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObjectId;
+
+/**
+ * Utility builder class for TAPI topology creation with DCS.
+ */
+public final class TapiTopologyBuilder extends TapiInstanceBuilder {
+
+    private DefaultTopology topology;
+
+    private TapiTopologyBuilder(DefaultTopology topology) {
+        this.topology = topology;
+        setUuid(this.topology);
+    }
+
+    public static TapiTopologyBuilder builder(DefaultTopology topology) {
+        return new TapiTopologyBuilder(topology);
+    }
+
+
+    @Override
+    public ModelObjectData build() {
+
+        DefaultAugmentedTapiCommonContext topologyContext = new DefaultAugmentedTapiCommonContext();
+        topologyContext.addToTopology(topology);
+
+        ModelObjectId objId = ModelObjectId.builder().addChild(DefaultContext.class).build();
+        return getModelObjectData(topologyContext, objId);
+    }
+
+    @Override
+    public ModelObject getModelObject() {
+        return topology;
+    }
+
+    @Override
+    public Uuid getUuid() {
+        return topology.uuid();
+    }
+
+}
diff --git a/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/package-info.java b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/package-info.java
new file mode 100644
index 0000000..8d71ec1
--- /dev/null
+++ b/apps/odtn/api/src/main/java/org/onosproject/odtn/utils/tapi/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.
+ */
+
+/**
+ * Utilities to deal with onos-yang-tools TAPI objects.
+ */
+package org.onosproject.odtn.utils.tapi;
\ No newline at end of file