Merge dev/fluorine work across to master
[unimgr.git] / impl / src / main / java / org / opendaylight / unimgr / mef / nrp / common / NrpDao.java
index d1fbcc20e2f4253ea4c5134f532730eda8cec6cf..4db618348eb70fe463c9a7f9616f5eda89594973 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.unimgr.mef.nrp.common;
 
+import com.google.common.base.Optional;
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Objects;
 import java.util.function.Function;
 import java.util.stream.Stream;
 
@@ -17,76 +20,126 @@ import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.unimgr.mef.nrp.api.TapiConstants;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.Context;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.ETH;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.LayerProtocolName;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.Uuid;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.context.attrs.ServiceInterfacePoint;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.common.rev171113.context.attrs.ServiceInterfacePointKey;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.connectivity.context.Connection;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.connectivity.context.ConnectionKey;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.connectivity.context.ConnectivityService;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.connectivity.context.ConnectivityServiceKey;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.Context1;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.node.OwnedNodeEdgePoint;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.node.OwnedNodeEdgePointKey;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.node.TransferCostBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.node.TransferTimingBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.topology.context.Topology;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.topology.context.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.topology.NodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.topology.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.transfer.cost.pac.CostCharacteristic;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.transfer.cost.pac.CostCharacteristicBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.transfer.timing.pac.LatencyCharacteristic;
-import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.topology.rev171113.transfer.timing.pac.LatencyCharacteristicBuilder;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.nrp._interface.rev180321.EndPoint1;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.nrp._interface.rev180321.EndPoint1Builder;
+import org.opendaylight.yang.gen.v1.urn.mef.yang.nrp._interface.rev180321.EndPoint7;
+import org.opendaylight.yang.gen.v1.urn.odl.unimgr.yang.unimgr.ext.rev170531.NodeAdiAugmentation;
+import org.opendaylight.yang.gen.v1.urn.odl.unimgr.yang.unimgr.ext.rev170531.NodeAdiAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.odl.unimgr.yang.unimgr.ext.rev170531.NodeSvmAugmentation;
+import org.opendaylight.yang.gen.v1.urn.odl.unimgr.yang.unimgr.ext.rev170531.NodeSvmAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.odl.unimgr.yang.unimgr.ext.rev170531.context.topology.node.ServiceVlanMap;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.Context;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.LayerProtocolName;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.ServiceInterfacePointRef;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.Uuid;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.tapi.context.ServiceInterfacePoint;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev180307.tapi.context.ServiceInterfacePointKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.ConnectionEndPointRef;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.OwnedNodeEdgePoint1;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.OwnedNodeEdgePoint1Builder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.cep.list.ConnectionEndPoint;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.cep.list.ConnectionEndPointKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connection.ConnectionEndPointBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.context.Connection;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.context.ConnectionKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.context.ConnectivityService;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.context.ConnectivityServiceKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.service.EndPoint;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.service.EndPointBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.connectivity.service.EndPointKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.Context1;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.OwnedNodeEdgePointRef;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.node.OwnedNodeEdgePoint;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.node.OwnedNodeEdgePointBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.node.OwnedNodeEdgePointKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.topology.context.Topology;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev180307.topology.context.TopologyKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
+
 
 /**
+ * Nrp data access methods to simplify interaction with model.
  * @author bartosz.michalik@amartus.com
  */
 public class NrpDao  {
     private static final Logger LOG = LoggerFactory.getLogger(NrpDao.class);
+    private static final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
+            .tapi.connectivity.rev180307.Context1> CS_CTX
+            = ctx().augmentation(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang
+            .tapi.connectivity.rev180307.Context1.class);
+
     private final ReadWriteTransaction tx;
     private final ReadTransaction rtx;
 
-
     public NrpDao(ReadWriteTransaction tx) {
-        if(tx == null) throw new NullPointerException();
+        if (tx == null) {
+            throw new NullPointerException();
+        }
         this.tx = tx;
         this.rtx = tx;
     }
+
     public NrpDao(ReadOnlyTransaction tx) {
         this.rtx = tx;
         this.tx =  null;
     }
 
-    public Node createNode(String topologyId, String nodeId, Class<? extends LayerProtocolName> name, List<OwnedNodeEdgePoint> neps) {
+    public Node createNode(String topologyId, String nodeId, LayerProtocolName name, List<OwnedNodeEdgePoint> neps) {
+        return createNode(topologyId, nodeId, nodeId, name, neps);
+    }
+
+    public Node createNode(String topologyId, String nodeId, String activationDriverId,
+                       LayerProtocolName name, List<OwnedNodeEdgePoint> neps) {
+        return createNode(topologyId, nodeId, activationDriverId, name, neps,null);
+    }
+
+    public Node createNode(String topologyId, String nodeId, String activationDriverId,
+                       LayerProtocolName name, List<OwnedNodeEdgePoint> neps, List<ServiceVlanMap> serviceVlanMapList) {
         verifyTx();
+        assert tx != null;
         Uuid uuid = new Uuid(nodeId);
 
-        Node node = new NodeBuilder()
-                .setKey(new NodeKey(uuid))
+        NodeBuilder nb = new NodeBuilder()
+                .withKey(new NodeKey(uuid))
                 .setUuid(uuid)
                 .setLayerProtocolName(Collections.singletonList(name))
-                .setTransferCost(new TransferCostBuilder().setCostCharacteristic(TapiUtils.emptyCostCharacteristic()).build())
-                .setTransferTiming(new TransferTimingBuilder().setLatencyCharacteristic(TapiUtils.emptyTransferCost()).build())
                 .setOwnedNodeEdgePoint(neps)
-                .build();
+                .setCostCharacteristic(Collections.emptyList())
+                .setLatencyCharacteristic(Collections.emptyList())
+                .addAugmentation(NodeAdiAugmentation.class, new NodeAdiAugmentationBuilder()
+                        .setActivationDriverId(activationDriverId).build());
+
+        Node node = serviceVlanMapList == null ? nb.build() : nb.addAugmentation(NodeSvmAugmentation.class,
+                new NodeSvmAugmentationBuilder().setServiceVlanMap(serviceVlanMapList).build()).build();
         tx.put(LogicalDatastoreType.OPERATIONAL, node(nodeId), node);
         return node;
     }
 
+    /**
+     * Update node or add if it does not exist.
+     * @param node to be updated (or added)
+     * <p>
+     * Note: Please bare in mind that all external changes between reading/modifying
+     *             the node given as parameter and writing it are silently lost
+     * </p>
+     */
+    public void updateNode(Node node) {
+        verifyTx();
+        tx.put(LogicalDatastoreType.OPERATIONAL, node(node.getUuid()), node);
+    }
+
     private void verifyTx() {
         if (tx == null) {
-            throw new IllegalStateException("Top perform write operation read write transaction is needed");
+            throw new IllegalStateException("To perform write operation read write transaction is needed");
         }
     }
 
@@ -101,20 +154,25 @@ public class NrpDao  {
 
     public void updateNep(Uuid nodeId, OwnedNodeEdgePoint nep) {
         verifyTx();
-        InstanceIdentifier<OwnedNodeEdgePoint> nodeIdent = node(nodeId).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nep.getUuid()));
+        InstanceIdentifier<OwnedNodeEdgePoint> nodeIdent = node(nodeId).child(OwnedNodeEdgePoint.class,
+                new OwnedNodeEdgePointKey(nep.getUuid()));
+        assert tx != null;
         tx.put(LogicalDatastoreType.OPERATIONAL, nodeIdent, nep);
     }
 
     public void removeNep(String nodeId, String nepId, boolean removeSips) {
         verifyTx();
-        InstanceIdentifier<OwnedNodeEdgePoint> nepIdent = node(nodeId).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(new Uuid(nepId)));
+        assert tx != null;
+        InstanceIdentifier<OwnedNodeEdgePoint> nepIdent = node(nodeId).child(OwnedNodeEdgePoint.class,
+                new OwnedNodeEdgePointKey(new Uuid(nepId)));
         try {
-            Optional<OwnedNodeEdgePoint> opt = tx.read(LogicalDatastoreType.OPERATIONAL, nepIdent).checkedGet();
+            Optional<OwnedNodeEdgePoint> opt = rtx.read(LogicalDatastoreType.OPERATIONAL, nepIdent).checkedGet();
             if (opt.isPresent()) {
                 tx.delete(LogicalDatastoreType.OPERATIONAL,nepIdent);
                 if (removeSips) {
-                    List<Uuid> sips = opt.get().getMappedServiceInterfacePoint();
-                    removeSips(sips == null ? null : sips.stream());
+                    Stream<Uuid> sips = opt.get().getMappedServiceInterfacePoint().stream()
+                            .map(ServiceInterfacePointRef::getServiceInterfacePointId);
+                    removeSips(sips);
                 }
             }
         } catch (ReadFailedException e) {
@@ -124,13 +182,64 @@ public class NrpDao  {
 
     public void addSip(ServiceInterfacePoint sip) {
         verifyTx();
+        assert tx != null;
         tx.put(LogicalDatastoreType.OPERATIONAL,
             ctx().child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(sip.getUuid())),
                 sip);
     }
 
+    private Function<OwnedNodeEdgePointRef, KeyedInstanceIdentifier<OwnedNodeEdgePoint, OwnedNodeEdgePointKey>> toPath =
+        ref -> topo(ref.getTopologyId())
+                .child(Node.class, new NodeKey(new Uuid(ref.getNodeId())))
+                .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(ref.getOwnedNodeEdgePointId()));
+
+    public org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307
+            .connection.ConnectionEndPoint addConnectionEndPoint(OwnedNodeEdgePointRef ref, ConnectionEndPoint cep) {
+        verifyTx();
+        assert tx != null;
+        OwnedNodeEdgePoint nep = null;
+        try {
+            nep = readNep(ref);
+        } catch (ReadFailedException e) {
+            LOG.warn("Error while reading NEP", e);
+        }
+        if (nep == null) {
+            throw new IllegalArgumentException("Cannot find NEP for " + ref);
+        }
+
+        OwnedNodeEdgePoint1Builder builder;
+
+        OwnedNodeEdgePoint1 aug = nep.augmentation(OwnedNodeEdgePoint1.class);
+        if (aug == null) {
+            builder = new OwnedNodeEdgePoint1Builder();
+        } else {
+            builder = new OwnedNodeEdgePoint1Builder(aug);
+        }
+
+        List<ConnectionEndPoint> cepList = builder.getConnectionEndPoint();
+        if (cepList == null) {
+            cepList = new LinkedList<>();
+        }
+
+        cepList.add(cep);
+        builder.setConnectionEndPoint(cepList);
+
+        nep = new OwnedNodeEdgePointBuilder(nep).addAugmentation(OwnedNodeEdgePoint1.class, builder.build()).build();
+        tx.merge(LogicalDatastoreType.OPERATIONAL, toPath.apply(ref), nep);
+
+        return new ConnectionEndPointBuilder(ref).setConnectionEndPointId(cep.getUuid()).build();
+    }
+
+    public OwnedNodeEdgePoint readNep(OwnedNodeEdgePointRef ref) throws ReadFailedException {
+
+        KeyedInstanceIdentifier<OwnedNodeEdgePoint, OwnedNodeEdgePointKey> nepKey = toPath.apply(ref);
+
+        return rtx.read(LogicalDatastoreType.OPERATIONAL, nepKey).checkedGet().orNull();
+    }
+
     public OwnedNodeEdgePoint readNep(String nodeId, String nepId) throws ReadFailedException {
-        KeyedInstanceIdentifier<OwnedNodeEdgePoint, OwnedNodeEdgePointKey> nepKey = node(nodeId).child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(new Uuid(nepId)));
+        KeyedInstanceIdentifier<OwnedNodeEdgePoint, OwnedNodeEdgePointKey> nepKey = node(nodeId)
+                .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(new Uuid(nepId)));
         return rtx.read(LogicalDatastoreType.OPERATIONAL, nepKey).checkedGet().orNull();
     }
 
@@ -138,7 +247,8 @@ public class NrpDao  {
         Uuid universalId = new Uuid("sip:" + nepId);
         try {
             return rtx.read(LogicalDatastoreType.OPERATIONAL,
-                    ctx().child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(universalId))).checkedGet().isPresent();
+                    ctx().child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(universalId)))
+                    .checkedGet().isPresent();
         } catch (ReadFailedException e) {
             LOG.error("Cannot read sip with id {}", universalId.getValue());
         }
@@ -155,7 +265,13 @@ public class NrpDao  {
     }
 
     public Node getNode(String uuidTopo, String uuidNode) throws ReadFailedException {
-        Optional<Node> topology = rtx.read(LogicalDatastoreType.OPERATIONAL, node(new Uuid(uuidTopo), new Uuid(uuidNode))).checkedGet();
+        Optional<Node> topology = rtx.read(LogicalDatastoreType.OPERATIONAL,
+                node(new Uuid(uuidTopo), new Uuid(uuidNode))).checkedGet();
+        return topology.orNull();
+    }
+
+    public Node getNode(Uuid uuidNode) throws ReadFailedException {
+        Optional<Node> topology = rtx.read(LogicalDatastoreType.OPERATIONAL, node(uuidNode)).checkedGet();
         return topology.orNull();
     }
 
@@ -186,7 +302,8 @@ public class NrpDao  {
     }
 
     public static InstanceIdentifier<Node> abstractNode() {
-        return topo(TapiConstants.PRESTO_EXT_TOPO).child(Node.class, new NodeKey(new Uuid(TapiConstants.PRESTO_ABSTRACT_NODE)));
+        return topo(TapiConstants.PRESTO_EXT_TOPO).child(Node.class,
+                new NodeKey(new Uuid(TapiConstants.PRESTO_ABSTRACT_NODE)));
     }
 
     public void removeSip(Uuid uuid) {
@@ -195,12 +312,14 @@ public class NrpDao  {
 
     public void removeSips(Stream<Uuid>  uuids) {
         verifyTx();
+        assert tx != null;
         if (uuids == null) {
             return;
         }
         uuids.forEach(sip -> {
             LOG.debug("removing ServiceInterfacePoint with id {}", sip);
-            tx.delete(LogicalDatastoreType.OPERATIONAL, ctx().child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(sip)));
+            tx.delete(LogicalDatastoreType.OPERATIONAL, ctx().child(ServiceInterfacePoint.class,
+                    new ServiceInterfacePointKey(sip)));
         });
     }
 
@@ -208,48 +327,74 @@ public class NrpDao  {
         verifyTx();
         if (removeSips) {
             try {
-                Optional<Node> opt = tx.read(LogicalDatastoreType.OPERATIONAL, node(nodeId)).checkedGet();
+                Optional<Node> opt = rtx.read(LogicalDatastoreType.OPERATIONAL, node(nodeId)).checkedGet();
                 if (opt.isPresent()) {
-                    removeSips(opt.get().getOwnedNodeEdgePoint().stream().flatMap(nep -> nep.getMappedServiceInterfacePoint() == null
-                                                                                  ? Stream.empty()
-                                                                                  : nep.getMappedServiceInterfacePoint().stream()
-                    ));
+                    List<OwnedNodeEdgePoint> neps = opt.get().getOwnedNodeEdgePoint();
+                    if (neps != null) {
+                        removeSips(neps.stream().flatMap(nep -> nep.getMappedServiceInterfacePoint() == null
+                                ? Stream.empty()
+                                : nep.getMappedServiceInterfacePoint()
+                                    .stream().map(ServiceInterfacePointRef::getServiceInterfacePointId)
+                        ));
+                    }
                 }
             } catch (ReadFailedException e) {
                 LOG.error("Cannot read node with id {}", nodeId);
             }
         }
-
+        assert tx != null;
         tx.delete(LogicalDatastoreType.OPERATIONAL, node(nodeId));
     }
 
     public void updateAbstractNep(OwnedNodeEdgePoint nep) {
         verifyTx();
-        InstanceIdentifier<OwnedNodeEdgePoint> nodeIdent = abstractNode().child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nep.getUuid()));
+        assert tx != null;
+        InstanceIdentifier<OwnedNodeEdgePoint> nodeIdent = abstractNode().child(OwnedNodeEdgePoint.class,
+                new OwnedNodeEdgePointKey(nep.getUuid()));
         tx.merge(LogicalDatastoreType.OPERATIONAL, nodeIdent, nep);
     }
 
     public void deleteAbstractNep(OwnedNodeEdgePoint nep) {
         verifyTx();
-        InstanceIdentifier<OwnedNodeEdgePoint> nodeIdent = abstractNode().child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nep.getUuid()));
+        assert tx != null;
+        InstanceIdentifier<OwnedNodeEdgePoint> nodeIdent = abstractNode().child(OwnedNodeEdgePoint.class,
+                new OwnedNodeEdgePointKey(nep.getUuid()));
         tx.delete(LogicalDatastoreType.OPERATIONAL, nodeIdent);
     }
 
     public List<ConnectivityService> getConnectivityServiceList() {
         try {
-            org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.Context1 connections = rtx.read(LogicalDatastoreType.OPERATIONAL,
-                    ctx().augmentation(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.Context1.class))
+            org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307.Context1 connectivity = rtx
+                    .read(LogicalDatastoreType.OPERATIONAL, CS_CTX)
                     .checkedGet().orNull();
-            return connections == null ? null : connections.getConnectivityService();
+            return connectivity == null ? null : connectivity.getConnectivityService();
         } catch (ReadFailedException e) {
             LOG.warn("reading connectivity services failed", e);
             return null;
         }
     }
 
+    public ConnectivityService getConnectivityService(String idOrName) {
+        ConnectivityService cs = getConnectivityService(new Uuid(idOrName));
+        if (cs != null) {
+            return cs;
+        }
+
+        List<ConnectivityService> csList = getConnectivityServiceList();
+        if (csList != null) {
+            return csList.stream()
+                    .filter(child -> child.getName() != null && child.getName().stream()
+                            .anyMatch(n -> idOrName.equals(n.getValue())))
+                    .findFirst().orElse(null);
+
+        }
+        return null;
+    }
+
     public ConnectivityService getConnectivityService(Uuid id) {
         try {
-            return rtx.read(LogicalDatastoreType.OPERATIONAL, ctx().augmentation(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.Context1.class).child(ConnectivityService.class, new ConnectivityServiceKey(id)))
+            return rtx.read(LogicalDatastoreType.OPERATIONAL, CS_CTX
+                    .child(ConnectivityService.class, new ConnectivityServiceKey(id)))
                     .checkedGet().orNull();
 
         } catch (ReadFailedException e) {
@@ -258,18 +403,31 @@ public class NrpDao  {
         }
     }
 
-    public ServiceInterfacePoint getSip(String sipId) throws ReadFailedException {
-        KeyedInstanceIdentifier<ServiceInterfacePoint, ServiceInterfacePointKey> key = ctx().child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(new Uuid(sipId)));
-        return rtx.read(LogicalDatastoreType.OPERATIONAL, key).checkedGet().orNull();
+    public OwnedNodeEdgePoint getNepByCep(ConnectionEndPointRef ref) {
+        KeyedInstanceIdentifier<OwnedNodeEdgePoint, OwnedNodeEdgePointKey> nepPath =
+                node(ref.getTopologyId(), ref.getNodeId())
+                        .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(ref.getOwnedNodeEdgePointId()));
+
+        try {
+            return rtx.read(LogicalDatastoreType.OPERATIONAL, nepPath)
+                    .checkedGet().orNull();
+
+        } catch (ReadFailedException e) {
+            LOG.warn("reading NEP for ref " +  ref + " failed", e);
+            return null;
+        }
     }
 
-    public ConnectivityService getConnectivityService(String id) {
-        return getConnectivityService(new Uuid(id));
+    public ServiceInterfacePoint getSip(String sipId) throws ReadFailedException {
+        KeyedInstanceIdentifier<ServiceInterfacePoint, ServiceInterfacePointKey> key = ctx()
+                .child(ServiceInterfacePoint.class, new ServiceInterfacePointKey(new Uuid(sipId)));
+        return rtx.read(LogicalDatastoreType.OPERATIONAL, key).checkedGet().orNull();
     }
 
     public Connection getConnection(Uuid connectionId) {
         try {
-            return rtx.read(LogicalDatastoreType.OPERATIONAL, ctx().augmentation(org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.tapi.connectivity.rev171113.Context1.class).child(Connection.class, new ConnectionKey(connectionId)))
+            return rtx.read(LogicalDatastoreType.OPERATIONAL, CS_CTX.child(Connection.class,
+                    new ConnectionKey(connectionId)))
                     .checkedGet().orNull();
 
         } catch (ReadFailedException e) {
@@ -277,4 +435,60 @@ public class NrpDao  {
             return null;
         }
     }
+
+    public String getActivationDriverId(Uuid nodeUuid) throws ReadFailedException {
+        return getNode(nodeUuid).augmentation(NodeAdiAugmentation.class).getActivationDriverId();
+    }
+
+    public void removeConnection(Uuid connectionId) {
+        Objects.requireNonNull(connectionId);
+        verifyTx();
+        assert tx != null;
+        Connection connection = getConnection(connectionId);
+        if (connection == null) {
+            return;
+        }
+
+        for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307
+                .connection.ConnectionEndPoint cepRef : connection.getConnectionEndPoint()) {
+            KeyedInstanceIdentifier<ConnectionEndPoint, ConnectionEndPointKey> cepKey =
+                    node(cepRef.getTopologyId(), cepRef.getNodeId())
+                    .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(cepRef.getOwnedNodeEdgePointId()))
+                    .augmentation(OwnedNodeEdgePoint1.class).child(ConnectionEndPoint.class,
+                            new ConnectionEndPointKey(cepRef.getConnectionEndPointId()));
+            tx.delete(LogicalDatastoreType.OPERATIONAL,cepKey);
+        }
+        LOG.debug("removing connection {}", connectionId.getValue());
+        tx.delete(LogicalDatastoreType.OPERATIONAL, CS_CTX.child(Connection.class, new ConnectionKey(connectionId)));
+    }
+
+    public ConnectivityService updateCsEndPoint(String serviceId,
+            org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307
+            .update.connectivity.service.input.EndPoint endPoint) throws TransactionCommitFailedException {
+        Objects.requireNonNull(endPoint);
+        Objects.requireNonNull(serviceId);
+        org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev180307
+                .connectivity.service.EndPoint ep = new EndPointBuilder(endPoint).build();
+
+
+        KeyedInstanceIdentifier<EndPoint, EndPointKey> epId = CS_CTX
+                .child(ConnectivityService.class, new ConnectivityServiceKey(new Uuid(serviceId)))
+                .child(EndPoint.class, new EndPointKey(endPoint.getLocalId()));
+
+        tx.put(LogicalDatastoreType.OPERATIONAL, epId, ep);
+        if (endPoint.augmentation(EndPoint7.class) != null) {
+            tx.put(LogicalDatastoreType.OPERATIONAL, epId.augmentation(EndPoint1.class),
+                    new EndPoint1Builder(endPoint.augmentation(EndPoint7.class)).build());
+        }
+        //XXX do we need to support name as well?
+        ConnectivityService cs = getConnectivityService(serviceId);
+        try {
+            tx.submit().checkedGet();
+        } catch (TransactionCommitFailedException e) {
+            LOG.warn("Problem with updatign connectivity service endpoint", e);
+            throw e;
+        }
+
+        return cs;
+    }
 }