From f9c9e7656939a8dd934ffd69c98e015e159c4bff Mon Sep 17 00:00:00 2001 From: Mohamed El-Serngawy Date: Tue, 17 Nov 2015 12:58:25 -0500 Subject: [PATCH] uni show and list commands Change-Id: Iac5914c9d205088a06ce1dd4318666a4fa74aa96 Signed-off-by: Mohamed El-Serngawy --- .../unimgr/cli/UniListShellCommand.java | 10 ++-- .../unimgr/cli/UniShowShellCommand.java | 10 ++-- .../unimgr/api/IUnimgrConsoleProvider.java | 5 +- .../unimgr/impl/UnimgrProvider.java | 11 ++--- .../opendaylight/unimgr/impl/UnimgrUtils.java | 48 +++++++++++++++++++ 5 files changed, 65 insertions(+), 19 deletions(-) diff --git a/cli/src/main/java/org/opendaylight/unimgr/cli/UniListShellCommand.java b/cli/src/main/java/org/opendaylight/unimgr/cli/UniListShellCommand.java index a210b898..988c1f7a 100755 --- a/cli/src/main/java/org/opendaylight/unimgr/cli/UniListShellCommand.java +++ b/cli/src/main/java/org/opendaylight/unimgr/cli/UniListShellCommand.java @@ -16,8 +16,9 @@ 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.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation; -@Command(name = "list", scope = "uni", description = "Lists all uni in the controller.") +@Command(name = "uni-list", scope = "uni", description = "Lists all uni in the controller.") public class UniListShellCommand extends OsgiCommandSupport { protected IUnimgrConsoleProvider provider; @@ -36,14 +37,15 @@ public class UniListShellCommand extends OsgiCommandSupport { @Override protected Object doExecute() throws Exception { - List listUnis = provider.listUnis(isConfigurationData); + LogicalDatastoreType storeType = isConfigurationData ? LogicalDatastoreType.CONFIGURATION : LogicalDatastoreType.OPERATIONAL; + List listUnis = provider.listUnis(storeType); if (listUnis.size() > 0) { StringBuilder sb = new StringBuilder(); Integer counter = 1; - for (Uni uni : listUnis) { + for (UniAugmentation uni : listUnis) { // TODO - sb.append(String.format("#%d - id: %s\n", counter, uni.getIpAddress().getIpv4Address())); + sb.append(String.format("#%d - IpAddress: %s\n", counter, uni.getIpAddress().getIpv4Address().getValue())); counter++; } return sb.toString(); diff --git a/cli/src/main/java/org/opendaylight/unimgr/cli/UniShowShellCommand.java b/cli/src/main/java/org/opendaylight/unimgr/cli/UniShowShellCommand.java index eeb02e2d..0df6db21 100755 --- a/cli/src/main/java/org/opendaylight/unimgr/cli/UniShowShellCommand.java +++ b/cli/src/main/java/org/opendaylight/unimgr/cli/UniShowShellCommand.java @@ -12,9 +12,9 @@ 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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation; -@Command(name = "show", scope = "uni", description = "Shows detailed information about an uni.") +@Command(name = "uni-show", scope = "uni", description = "Shows detailed information about an uni.") public class UniShowShellCommand extends OsgiCommandSupport { protected IUnimgrConsoleProvider provider; @@ -30,12 +30,12 @@ public class UniShowShellCommand extends OsgiCommandSupport { protected Object doExecute() throws Exception { StringBuilder sb = new StringBuilder(); IpAddress ipAddre = new IpAddress(ipAddress.toCharArray()); - Uni uni = provider.getUni(ipAddre); + UniAugmentation uni = provider.getUni(ipAddre); if (uni != null) { - //sb.append(String.format("Uni Id: <%s>\n", uni.getUniId())); - sb.append(String.format("Physical medium: <%s>\n", uni.getPhysicalMedium())); + sb.append(String.format("Ip Address: <%s>\n", uni.getIpAddress().getIpv4Address().getValue())); sb.append(String.format("Mac address: <%s>\n", uni.getMacAddress())); + sb.append(String.format("Physical medium: <%s>\n", uni.getPhysicalMedium())); sb.append(String.format("Speed: " + uni.getSpeed() + "\n")); sb.append(String.format("Mode: <%s>\n", uni.getMode())); sb.append(String.format("Mac layer: <%s>\n", uni.getMacLayer())); diff --git a/impl/src/main/java/org/opendaylight/unimgr/api/IUnimgrConsoleProvider.java b/impl/src/main/java/org/opendaylight/unimgr/api/IUnimgrConsoleProvider.java index 1346649d..c4fc4ce1 100755 --- a/impl/src/main/java/org/opendaylight/unimgr/api/IUnimgrConsoleProvider.java +++ b/impl/src/main/java/org/opendaylight/unimgr/api/IUnimgrConsoleProvider.java @@ -12,7 +12,6 @@ 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 { @@ -21,9 +20,9 @@ public interface IUnimgrConsoleProvider extends AutoCloseable { boolean removeUni(IpAddress ipAddress); - List listUnis(Boolean isConfigurationData); + List listUnis(LogicalDatastoreType dataStoreType); - Uni getUni(IpAddress ipAddress); + UniAugmentation getUni(IpAddress ipAddress); boolean removeEvc(String uuid); diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrProvider.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrProvider.java index beb31dc6..4bc29f54 100755 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrProvider.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrProvider.java @@ -20,7 +20,6 @@ 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; @@ -143,15 +142,13 @@ public class UnimgrProvider implements BindingAwareProvider, AutoCloseable, IUni } @Override - public List listUnis(Boolean isConfigurationData) { - // TODO Auto-generated method stub - return null; + public List listUnis(LogicalDatastoreType dataStoreType) { + return UnimgrUtils.getUnis(dataBroker, dataStoreType); } @Override - public Uni getUni(IpAddress ipAddress) { - // TODO Auto-generated method stub - return null; + public UniAugmentation getUni(IpAddress ipAddress) { + return UnimgrUtils.getUni(dataBroker, LogicalDatastoreType.CONFIGURATION, ipAddress); } diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java index edc213b1..5195edda 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java @@ -741,6 +741,54 @@ public class UnimgrUtils { return uniNodes; } + /** + * Retrieve a list of Unis on a specific DataStore + * @param dataBroker instance to create transactions + * @param store to which send the read request + * @return A List of Unis. + */ + public static List getUnis(DataBroker dataBroker, + LogicalDatastoreType store) { + List unis = new ArrayList<>(); + InstanceIdentifier 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) { + unis.add(uniAugmentation); + } + } + } + return unis; + } + + /** + * Retrieve a list of Unis on a specific DataStore + * @param dataBroker instance to create transactions + * @param store to which send the read request + * @param ipAddress of the required Uni + * @return uni. + */ + public static UniAugmentation getUni(DataBroker dataBroker, + LogicalDatastoreType store, IpAddress ipAddress) { + InstanceIdentifier 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 && uniAugmentation.getIpAddress().getIpv4Address().getValue().equals(ipAddress.getIpv4Address().getValue())) { + return uniAugmentation; + } + } + } + return null; + } + /** * Read a specific datastore type and return a DataObject as a casted * class type Object. -- 2.36.6