private static final Logger LOG = LoggerFactory.getLogger(EvcCreateCommand.class);
public EvcCreateCommand(DataBroker dataBroker,
- Map<InstanceIdentifier<?>, DataObject> changes) {
+ Map<InstanceIdentifier<?>, DataObject> changes) {
super.dataBroker = dataBroker;
super.changes = changes;
}
if (evc.getUniSource().iterator().next().getUni() != null) {
sourceUniIid = (InstanceIdentifier<Node>) evc.getUniSource().iterator().next().getUni();
} else {
- sourceUniIid = UnimgrMapper.createUniIid(dataBroker, evc.getUniSource().iterator().next().getIpAddress());
+ sourceUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniSource().iterator().next().getIpAddress());
}
if (evc.getUniDest().iterator().next().getUni() != null) {
- destinationUniIid = UnimgrMapper.createUniIid(dataBroker, evc.getUniDest().iterator().next().getIpAddress());;
+ destinationUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniDest().iterator().next().getIpAddress());;
} else {
destinationUniIid = (InstanceIdentifier<Node>) evc.getUniDest().iterator().next().getUni();
}
}
// Set source and destination
InstanceIdentifier<Node> sourceBridgeIid =
- UnimgrMapper.getOvsdbBridgeNodeIID(uniSource.getNodeId(),
+ UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(),
UnimgrConstants.DEFAULT_BRIDGE_NAME);
Optional<Node> optionalSourceBr = UnimgrUtils.readNode(dataBroker,
LogicalDatastoreType.CONFIGURATION,
sourceBridgeIid);
InstanceIdentifier<Node> destinationBridgeIid =
- UnimgrMapper.getOvsdbBridgeNodeIID(uniSource.getNodeId(),
+ UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(),
UnimgrConstants.DEFAULT_BRIDGE_NAME);
Optional<Node> optionalDestinationBr = UnimgrUtils.readNode(dataBroker,
LogicalDatastoreType.CONFIGURATION,
ovsdbNode = UnimgrUtils.createOvsdbNode(dataBroker,
uni);
LOG.info("Could not retrieve the OVSDB node,"
- + "created a new one: {}", ovsdbNode.getNodeId());
+ + " created a new one: {}", ovsdbNode.getNodeId());
UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION,
uniKey,
uni,
ovsdbIid);
if (optionalOvsdbNode.isPresent()) {
InstanceIdentifier<Node> uniIid =
- UnimgrMapper.createUniIid(dataBroker,
- uniAugmentation.getIpAddress());
+ UnimgrMapper.getUniIid(dataBroker,
+ uniAugmentation.getIpAddress(),
+ LogicalDatastoreType.CONFIGURATION);
UnimgrUtils.createBridgeNode(dataBroker,
ovsdbIid,
uniAugmentation,
.getConnectionInfo()
.getRemoteIp()
.equals(uniAugmentation.getIpAddress())) {
- InstanceIdentifier<Node> uniIid = UnimgrMapper.createUniIid(dataBroker,
- uniAugmentation.getIpAddress());
+ InstanceIdentifier<Node> uniIid = UnimgrMapper.getUniIid(dataBroker,
+ uniAugmentation.getIpAddress(),
+ LogicalDatastoreType.CONFIGURATION);
UnimgrUtils.createBridgeNode(dataBroker,
ovsdbIid,
uniAugmentation,
this.invoker = invoker;
listeners = new HashSet<ListenerRegistration<DataChangeListener>>();
listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- UnimgrMapper.createUniIid(),
+ UnimgrMapper.getUniTopologyIid(),
this,
DataChangeScope.SUBTREE));
listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
- UnimgrMapper.createEvcIid(),
+ UnimgrMapper.getEvcTopologyIid(),
this,
DataChangeScope.SUBTREE));
listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- UnimgrMapper.getOvsdbTopologyIdentifier(),
+ UnimgrMapper.getOvsdbTopologyIid(),
this,
DataChangeScope.SUBTREE));
}
import java.util.List;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class UnimgrMapper {
- private static final Logger LOG = LoggerFactory.getLogger(UnimgrMapper.class);
+ public static InstanceIdentifier<Link> getEvcLinkIID(LinkId id) {
+ InstanceIdentifier<Link> linkPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Link.class,
+ new LinkKey(id));
+ return linkPath;
+ }
+
+ public static InstanceIdentifier<Topology> getEvcTopologyIid() {
+ InstanceIdentifier<Topology> topoPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID));
+ return topoPath;
+ }
- public static InstanceIdentifier<Node> getOvsdbNodeIID(NodeId nodeId) {
+ public static InstanceIdentifier<Node> getEvcTopologyNodeIid() {
InstanceIdentifier<Node> nodePath = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,
- new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class,
- new NodeKey(nodeId));
+ new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
+ .child(Node.class);
return nodePath;
}
- public static InstanceIdentifier<Node> getOvsdbBridgeNodeIID(NodeId ovsdbNode,
+ public static InstanceIdentifier<Node> getOvsdbBridgeNodeIid(NodeId ovsdbNode,
String bridgeName) {
- NodeId bridgeNodeId = new NodeId(ovsdbNode + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX + bridgeName);
+ String ovsdbNodeId = ovsdbNode.getValue();
+ NodeId bridgeNodeId = new NodeId(ovsdbNodeId
+ + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
+ + bridgeName);
InstanceIdentifier<Node> nodePath = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,
return nodePath;
}
- public static InstanceIdentifier<Node> getOvsdbNodeIID(IpAddress ipAddress) {
+ public static InstanceIdentifier<Node> getOvsdbNodeIid(IpAddress ipAddress) {
String nodeId = UnimgrConstants.OVSDB_PREFIX
- + ipAddress.getIpv4Address().getValue().toString()
- + ":"
- + UnimgrConstants.OVSDB_PORT;
+ + ipAddress.getIpv4Address().getValue().toString()
+ + ":"
+ + UnimgrConstants.OVSDB_PORT;
InstanceIdentifier<Node> nodePath = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,
return nodePath;
}
- public static InstanceIdentifier<Node> getOvsdbTopologyIdentifier() {
- InstanceIdentifier<Node> path = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class);
- return path;
+ public static InstanceIdentifier<Node> getOvsdbNodeIid(NodeId nodeId) {
+ InstanceIdentifier<Node> nodePath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class,
+ new NodeKey(nodeId));
+ return nodePath;
+ }
+
+ public static InstanceIdentifier<Topology> getOvsdbTopologyIid() {
+ InstanceIdentifier<Topology> topoPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID));
+ return topoPath;
}
- public static InstanceIdentifier<TerminationPoint> createTerminationPointInstanceIdentifier(
+ public static InstanceIdentifier<TerminationPoint> getTerminationPointIid(
Node bridgeNode,
String portName) {
InstanceIdentifier<TerminationPoint> terminationPointPath =
.create(NetworkTopology.class)
.child(Topology.class,
new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class,bridgeNode.getKey())
+ .child(Node.class, bridgeNode.getKey())
.child(TerminationPoint.class,
new TerminationPointKey(new TpId(portName)));
-
- LOG.debug("Termination point InstanceIdentifier generated : {}",terminationPointPath);
return terminationPointPath;
}
- public static InstanceIdentifier<Node> createUniIid() {
- InstanceIdentifier<Node> iid = InstanceIdentifier.create(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
- .child(Node.class);
- return iid;
- }
-
- public static InstanceIdentifier<Node> createUniIid(DataBroker dataBroker,
- IpAddress ip) {
- List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker);
- for (Node node: uniNodes) {
+ public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
+ IpAddress ip) {
+ List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
+ LogicalDatastoreType.OPERATIONAL);
+ for (Node node : uniNodes) {
UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
if (uniAugmentation.getIpAddress().equals(ip)) {
InstanceIdentifier<Node> uniNode = InstanceIdentifier
return null;
}
- public static InstanceIdentifier<Node> createEvcIid() {
- InstanceIdentifier<Node> iid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
- .child(Node.class);
- return iid;
+ public static InstanceIdentifier<Node> getUniIid(DataBroker dataBroker,
+ IpAddress ip,
+ LogicalDatastoreType store) {
+ List<Node> uniNodes = UnimgrUtils.getUniNodes(dataBroker,
+ store);
+ for (Node node : uniNodes) {
+ UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation.getIpAddress().equals(ip)) {
+ InstanceIdentifier<Node> uniNode = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class,
+ new NodeKey(node.getKey()));
+ return uniNode;
+ }
+ }
+ return null;
}
- public static InstanceIdentifier<Topology> createTopologyIid() {
- InstanceIdentifier<Topology> iid = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class,
- new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID));
- return iid;
+ public static InstanceIdentifier<Topology> getUniTopologyIid() {
+ InstanceIdentifier<Topology> topoPath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID));
+ return topoPath;
}
- public static InstanceIdentifier<Link> getEvcLinkIID(LinkId id) {
- InstanceIdentifier<Link> linkPath = InstanceIdentifier
+ public static InstanceIdentifier<Node> getUniTopologyNodeIid() {
+ InstanceIdentifier<Node> nodePath = InstanceIdentifier
.create(NetworkTopology.class)
.child(Topology.class,
- new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID))
- .child(Link.class,new LinkKey(id));
- return linkPath;
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class);
+ return nodePath;
}
+
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey;
String bridgeName) {
LOG.info("Creating a bridge on node {}", ovsdbNodeId);
InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper
- .getOvsdbNodeIID(uni.getIpAddress());
+ .getOvsdbNodeIid(uni.getIpAddress());
ConnectionInfo connectionInfo = UnimgrUtils.getConnectionInfo(dataBroker, ovsdbNodeId);
if (connectionInfo != null) {
NodeBuilder bridgeNodeBuilder = new NodeBuilder();
InstanceIdentifier<Node> bridgeIid = UnimgrMapper
- .getOvsdbBridgeNodeIID(ovsdbNodeId, bridgeName);
+ .getOvsdbBridgeNodeIid(ovsdbNodeId, bridgeName);
NodeId bridgeNodeId = new NodeId(ovsdbNodeId
+ UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
+ bridgeName);
InstanceIdentifier<Node> ovsdbNodeIid = (InstanceIdentifier<Node>) uni.getOvsdbNodeRef().getValue();
if (ovsdbNodeIid != null) {
NodeBuilder bridgeNodeBuilder = new NodeBuilder();
- InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIID(ovsdbNode.getNodeId(),
+ InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(),
bridgeName);
NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId()
+ UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
ovsdbNodeIid);
if (optionalOvsdbNode.isPresent()) {
Node ovsdbNode = optionalOvsdbNode.get();
- InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIID(ovsdbNode.getNodeId(),
+ InstanceIdentifier<Node> bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(),
bridgeName);
- NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId()
+ NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId().getValue()
+ UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX
+ bridgeName);
bridgeNodeBuilder.setNodeId(bridgeNodeId);
String bridgeName,
String portName) {
InstanceIdentifier<TerminationPoint> tpIid =
- UnimgrMapper.createTerminationPointInstanceIdentifier(bridgeNode,
- portName);
+ UnimgrMapper.getTerminationPointIid(bridgeNode,
+ portName);
OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
new OvsdbTerminationPointAugmentationBuilder();
tpAugmentationBuilder.setName(portName);
public static void createOvsdbNode(DataBroker dataBroker,
NodeId ovsdbNodeId,
Uni uni) {
- InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(uni.getIpAddress());
+ InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(uni.getIpAddress());
try {
NodeKey ovsdbNodeKey = new NodeKey(ovsdbNodeId);
Node nodeData = new NodeBuilder()
UniAugmentation uni) {
NodeId ovsdbNodeId = new NodeId(createOvsdbNodeId(uni.getIpAddress()));
try {
- InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNodeId);
+ InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId);
NodeKey ovsdbNodeKey = new NodeKey(ovsdbNodeId);
Node nodeData = new NodeBuilder()
.setNodeId(ovsdbNodeId)
String portName,
String type) {
InstanceIdentifier<TerminationPoint> tpIid = UnimgrMapper
- .createTerminationPointInstanceIdentifier(bridgeNode,
- portName);
+ .getTerminationPointIid(bridgeNode,
+ portName);
OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
tpAugmentationBuilder.setName(portName);
if (type != null) {
public static ConnectionInfo getConnectionInfo(DataBroker dataBroker,
NodeId ovsdbNodeId) {
- InstanceIdentifier<Node> nodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNodeId);
+ InstanceIdentifier<Node> nodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId);
Optional<Node> node = readNode(dataBroker,
LogicalDatastoreType.OPERATIONAL,
nodeIid);
public static List<Link> getEvcLinks(DataBroker dataBroker,
IpAddress ipAddress) {
List<Link> evcLinks = new ArrayList<>();
- InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.createTopologyIid();
+ InstanceIdentifier<Topology> evcTopology = UnimgrMapper.getEvcTopologyIid();
Topology topology = UnimgrUtils.read(dataBroker,
LogicalDatastoreType.OPERATIONAL,
- topologyInstanceIdentifier);
- if (topology != null && topology.getNode() != null) {
+ evcTopology);
+ if (topology != null && topology.getLink() != null) {
for (Link link : topology.getLink()) {
EvcAugmentation evcAugmentation = link.getAugmentation(EvcAugmentation.class);
if (evcAugmentation != null) {
public static List<Node> getOvsdbNodes(DataBroker dataBroker) {
List<Node> ovsdbNodes = new ArrayList<>();
- InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.createTopologyIid();
+ InstanceIdentifier<Topology> ovsdbTopoIdentifier = UnimgrMapper.getOvsdbTopologyIid();
Topology topology = UnimgrUtils.read(dataBroker,
LogicalDatastoreType.OPERATIONAL,
- topologyInstanceIdentifier);
+ ovsdbTopoIdentifier);
if (topology != null && topology.getNode() != null) {
for (Node node : topology.getNode()) {
OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
public static List<Node> getUniNodes(DataBroker dataBroker) {
List<Node> uniNodes = new ArrayList<>();
- InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.createTopologyIid();
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
Topology topology = read(dataBroker,
LogicalDatastoreType.CONFIGURATION,
topologyInstanceIdentifier);
return uniNodes;
}
+ public static List<Node> getUniNodes(DataBroker dataBroker,
+ LogicalDatastoreType store) {
+ List<Node> uniNodes = new ArrayList<>();
+ InstanceIdentifier<Topology> topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid();
+ Topology topology = read(dataBroker,
+ store,
+ topologyInstanceIdentifier);
+ if (topology != null && topology.getNode() != null) {
+ for (Node node : topology.getNode()) {
+ UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class);
+ if (uniAugmentation != null) {
+ uniNodes.add(node);
+ }
+ }
+ }
+ return uniNodes;
+ }
+
public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
DataBroker dataBroker,
final LogicalDatastoreType store,
UniAugmentation uni,
Node ovsdbNode,
DataBroker dataBroker) {
- InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNode.getNodeId());
+ InstanceIdentifier<Node> ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId());
OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid);
UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni);
if (ovsdbNodeRef != null) {
updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
}
- Optional<Node> optionalNode = readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, uniKey);
+ Optional<Node> optionalNode = readNode(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ uniKey);
if (optionalNode.isPresent()) {
Node node = optionalNode.get();
WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
if (ovsdbNodeRef != null) {
updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef);
}
- Optional<Node> optionalNode = readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, uniKey);
+ Optional<Node> optionalNode = readNode(dataBroker,
+ LogicalDatastoreType.CONFIGURATION,
+ uniKey);
if (optionalNode.isPresent()) {
Node node = optionalNode.get();
WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();