import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed100MBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10GBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed10MBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.service.speed.speed.Speed1GBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.uni.Speed;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-@Command(name = "add",
+@Command(name = "uni-add",
scope = "uni",
description = "Adds an uni to the controller.")
public class UniAddShellCommand extends OsgiCommandSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(UniAddShellCommand.class);
protected IUnimgrConsoleProvider provider;
- @Option(name = "-id",
- aliases = { "--uni-id" },
- description = "The id.\n-id / --id <id>",
- required = true,
- multiValued = false)
- private String uniId = "any";
-
@Option(name = "-pm",
aliases = { "--physical-medium" },
description = "The physical medium.\n-pm / --physical-medium <physical-medium>",
required = false,
multiValued = false)
- private String physicalMedium = "any";
+ private String physicalMedium = "UNI TypeFull Duplex 2 Physical Interface";
@Option(name = "-ma",
aliases = { "--mac-address" },
description = "The mac address.\n-ma / --mac-address <mac-address>",
- required = false,
+ required = true,
multiValued = false)
private String macAddress = "any";
description = "The mode.\n-m / --mode <mode>",
required = false,
multiValued = false)
- private String mode = "any";
+ private String mode = "Full Duplex";
@Option(name = "-ml",
aliases = { "--mac-layer" },
description = "The mac layer.\n-ml / --mac-layer <mac-layer",
required = false,
multiValued = false)
- private String macLayer = "any";
+ private String macLayer = "IEEE 802.3-2005";
@Option(name = "-t",
aliases = { "--type" },
description = "The type.\n-t / --type <type>",
required = false,
multiValued = false)
- private String type = "any";
+ private String type = "";
@Option(name = "-ms",
aliases = { "--mtu-size" },
description = "The mtu size.\n-ms / --mtu-size <mtu-size>",
required = false,
multiValued = false)
- private String mtuSize;
+ private String mtuSize = "0";
@Option(name = "-s",
aliases = { "--speed" },
description = "Spped.\n-s / --speed 10M/100M/1G/10G",
- required = true,
+ required = false,
multiValued = true)
- private String speed = "any";
+ private String speed = "";
+
+ @Option(name = "-ip",
+ aliases = { "--ipAddress" },
+ description = "IpAddress of the Uni",
+ required = true,
+ multiValued = false)
+ private String ipAddress = "any";
public UniAddShellCommand(IUnimgrConsoleProvider provider) {
this.provider = provider;
}
private Object getSpeed() {
-
- System.out.println(speed);
-
Object speedObject = null;
if (speed.equals("10M")) {
speedObject = new Speed10MBuilder().build();
}
- if (speed.equals("100M")) {
+ else if (speed.equals("100M")) {
speedObject = new Speed100MBuilder().build();
}
- if (speed.equals("1G")) {
+ else if (speed.equals("1G")) {
speedObject = new Speed1GBuilder().build();
}
- if (speed.equals("10G")) {
+ else if (speed.equals("10G")) {
speedObject = new Speed10GBuilder().build();
}
- System.out.println(speedObject);
return speedObject;
}
@Override
protected Object doExecute() throws Exception {
- Uni uni = new UniAugmentationBuilder()
+ UniAugmentation uni = new UniAugmentationBuilder()
.setMacAddress(new MacAddress(macAddress))
.setMacLayer(macLayer)
.setMode(mode)
.setPhysicalMedium(physicalMedium)
.setSpeed((Speed) getSpeed())
.setType(type)
+ .setIpAddress(new IpAddress(ipAddress.toCharArray()))
.build();
if (provider.addUni(uni)) {
- return String.format("Uni created {}", uni.getIpAddress().getIpv4Address());
+ return new String("Uni with ip " +ipAddress+" created");
} else {
- return new String("Error creating new uni");
+ return new String("Error creating new Uni");
}
}
}
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
@Command(name = "remove", scope = "uni", description = "Removes an Uni from the controller.")
public class UniRemoveShellCommand extends OsgiCommandSupport {
protected IUnimgrConsoleProvider provider;
- @Argument(index = 0, name = "id", description = "Uni Id", required = true, multiValued = false)
- String id;
+ @Argument(index = 0, name = "ip", description = "Uni ipAddress", required = true, multiValued = false)
+ String ipAddress;
public UniRemoveShellCommand(IUnimgrConsoleProvider provider) {
this.provider = provider;
@Override
protected Object doExecute() throws Exception {
- if (provider.removeUni(id)) {
+ IpAddress ipAddre = new IpAddress(ipAddress.toCharArray());
+ if (provider.removeUni(ipAddre)) {
return String.format("Uni successfully removed");
} else {
return String.format("Error removing Uni");
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
+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.Uni;
@Command(name = "show", scope = "uni", description = "Shows detailed information about an uni.")
protected IUnimgrConsoleProvider provider;
- @Argument(index = 0, name = "id", description = "Uni Id", required = true, multiValued = false)
- String id;
+ @Argument(index = 0, name = "ip", description = "Uni ipAddress", required = true, multiValued = false)
+ String ipAddress;
public UniShowShellCommand(IUnimgrConsoleProvider provider) {
this.provider = provider;
@Override
protected Object doExecute() throws Exception {
StringBuilder sb = new StringBuilder();
- Uni uni = provider.getUni(id);
+ IpAddress ipAddre = new IpAddress(ipAddress.toCharArray());
+ Uni uni = provider.getUni(ipAddre);
if (uni != null) {
//sb.append(String.format("Uni Id: <%s>\n", uni.getUniId()));
import java.util.List;
+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.Evc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation;
public interface IUnimgrConsoleProvider extends AutoCloseable {
- boolean addUni(Uni uni);
+ boolean addUni(UniAugmentation uni);
- boolean removeUni(String uuid);
+ boolean removeUni(IpAddress ipAddress);
- List<Uni> listUnis(boolean isConfigurationDatastore);
+ List<Uni> listUnis(Boolean isConfigurationData);
- Uni getUni(String uuid);
+ Uni getUni(IpAddress ipAddress);
boolean removeEvc(String uuid);
public static final TopologyId EVC_TOPOLOGY_ID = new TopologyId(new Uri("unimgr:evc"));
+ public static final String UNI_PREFIX = "uni://";
+
public static final String OVSDB_PREFIX = "ovsdb://";
public static final Integer OVSDB_PORT = new Integer(6640);
return nodePath;
}
+ /**
+ * Generates an Instance Identifier for a specific UNI node by
+ * using the node Id
+ * @param nodeId The node ID of a specific UNI node.
+ * @return An Instance Identifier for a specific UNI node.
+ */
+ public static InstanceIdentifier<Node> getUniNodeIid(NodeId nodeId) {
+ InstanceIdentifier<Node> nodePath = InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class,
+ new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID))
+ .child(Node.class,
+ new NodeKey(nodeId));
+ return nodePath;
+}
}
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.opendaylight.unimgr.api.IUnimgrConsoleProvider;
import org.opendaylight.unimgr.command.TransactionInvoker;
+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.Evc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.Uni;
+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.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
private DataBroker dataBroker;
private ServiceRegistration<IUnimgrConsoleProvider> unimgrConsoleRegistration;
+ public UnimgrProvider() {
+ LOG.info("Unimgr provider initialized");
+ }
+
@Override
public void onSessionInitiated(ProviderContext session) {
LOG.info("UnimgrProvider Session Initiated");
}
@Override
- public boolean addUni(Uni uni) {
- //TODO This code was left commented as an example
- if (uni.getIpAddress() == null || uni.getMacAddress() == null) {
+ public boolean addUni(UniAugmentation uniAug) {
+ if (uniAug == null || uniAug.getIpAddress() == null || uniAug.getMacAddress() == null) {
return false;
}
-// UniAugmentation uniAugmentation = new UniAugmentationBuilder()
-// .setIpAddress(uni.getIpAddress())
-// .setMacAddress(uni.getMacAddress())
-// .build();
-// ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
-// InstanceIdentifier<Node> path = UnimgrMapper.getUniAugmentationIidByMac(uni.getMacAddress());
- return true;
+ return UnimgrUtils.createUniNode(dataBroker, uniAug);
}
@Override
- public boolean removeUni(String uuid) {
+ public boolean removeUni(IpAddress ipAddress) {
// TODO Auto-generated method stub
return false;
}
@Override
- public List<Uni> listUnis(boolean isConfigurationDatastore) {
+ public List<Uni> listUnis(Boolean isConfigurationData) {
// TODO Auto-generated method stub
return null;
}
@Override
- public Uni getUni(String uuid) {
+ public Uni getUni(IpAddress ipAddress) {
// TODO Auto-generated method stub
return null;
}
+
@Override
public boolean removeEvc(String uuid) {
// TODO Auto-generated method stub
return terminationPoint;
}
+ /**
+ * Creates and submit an UNI Node by using the Data contained in the UniAugmentation
+ * @param dataBroker The instance of the DataBroker to create transactions
+ * @param uni The UNI's data
+ * @return The instance of the UNI Node
+ */
+ public static boolean createUniNode(DataBroker dataBroker, UniAugmentation uni) {
+ NodeId uniNodeId = new NodeId(createUniNodeId(uni.getIpAddress()));
+ boolean result = false;
+ try {
+ InstanceIdentifier<Node> uniNodeIid = UnimgrMapper.getUniNodeIid(uniNodeId);
+ NodeKey uniNodeKey = new NodeKey(uniNodeId);
+ Node nodeData = new NodeBuilder()
+ .setNodeId(uniNodeId)
+ .setKey(uniNodeKey)
+ .addAugmentation(UniAugmentation.class, uni)
+ .build();
+ WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+ transaction.put(LogicalDatastoreType.CONFIGURATION, uniNodeIid, nodeData);
+ CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
+ future.checkedGet();
+ result = true;
+ LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId());
+ } catch (Exception e) {
+ LOG.error("Exception while creating Uni Node" + "Uni Node Id: {}", uniNodeId);
+ }
+ return result;
+ }
+
+ /**
+ * Creates an UNI node Id with an IP Address.
+ * @param ipAddress The IP address of the UNI
+ * @return A NodeId for a Specific UNI Node Id
+ */
+ public static NodeId createUniNodeId(IpAddress ipAddress) {
+ return new NodeId(UnimgrConstants.UNI_PREFIX + ipAddress.getIpv4Address().getValue().toString());
+ }
+
/**
* Creates and Submit a termination point Node to the configuration DateStore.
* @param dataBroker The instance of the data broker to create transactions
import org.opendaylight.unimgr.impl.UnimgrProvider;
public class UnimgrModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.impl.rev151012.AbstractUnimgrModule {
+
public UnimgrModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
--- /dev/null
+<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+</blueprint>
\ No newline at end of file