} catch (Exception e) {
logger.error("GossipRouter didn't start exception " + e
+ " met");
- StringWriter sw = new StringWriter();
logger.error("Stack Trace that raised the exception");
- e.printStackTrace(new PrintWriter(sw));
- logger.error(sw.toString());
+ logger.error("",e);
}
}
logger.info("Starting the ClusterManager");
logger.debug("Started the ClusterManager");
}
} catch (Exception ioe) {
- StringWriter sw = new StringWriter();
logger.error("Cannot configure infinispan .. bailing out ");
logger.error("Stack Trace that raised th exception");
- ioe.printStackTrace(new PrintWriter(sw));
- logger.error(sw.toString());
+ logger.error("",ioe);
this.cm = null;
this.stop();
}
<module>../../containermanager/api</module>
<module>../../containermanager/implementation</module>
<module>../../switchmanager</module>
- <module>../../statisticsmanager</module>
+ <module>../../statisticsmanager/api</module>
+ <module>../../statisticsmanager/implementation</module>
+ <module>../../statisticsmanager/integrationtest</module>
<module>../../topologymanager</module>
<module>../../usermanager</module>
<module>../../security</module>
<!-- Southbound bundles -->
<module>../../protocol_plugins/openflow</module>
+ <module>../../protocol_plugins/stub</module>
<!-- Samples -->
<module>../../samples/simpleforwarding</module>
import org.opendaylight.controller.sal.utils.NodeCreator;
import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This class defines a static route object.
*/
public class StaticRoute {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(StaticRoute.class);
+
/**
* This Enum defines the possible types for the next hop address.
*/
return InetAddress.getByAddress(BitBufferHelper
.toByteArray(netmask));
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
return null;
}
}
try {
return InetAddress.getByAddress(bbself.array());
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
}
try {
ra.staticRouteUpdate(s, update);
} catch (Exception e) {
- e.printStackTrace();
+ log.error("",e);
}
}
}
try {
host = future.get();
} catch (Exception e) {
- e.printStackTrace();
+ log.error("",e);
}
}
}
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.flowprogrammer.Flow;
import org.opendaylight.controller.sal.match.Match;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Represents a flow applications request Forwarding Rules Manager to install
* For instance the flows constituting a policy all share the same group name.
*/
public class FlowEntry implements Cloneable, Serializable {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(FlowEntry.class);
private static final long serialVersionUID = 1L;
private String groupName; // group name
private String flowName; // flow name (may be null)
cloned = (FlowEntry) super.clone();
cloned.flow = this.flow.clone();
} catch (CloneNotSupportedException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return cloned;
}
try {
node = NodeCreator.createOFNode(Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ log.error("",e);
}
ci.println(this.programmer.addFlow(node, getSampleFlow(node)));
}
try {
node = NodeCreator.createOFNode(Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ log.error("",e);
}
ci.println(this.programmer.removeFlow(node, getSampleFlow(node)));
}
import java.util.concurrent.Future;
import org.apache.felix.dm.Component;
+import org.apache.taglibs.standard.lang.jstl.DivideOperator;
import org.opendaylight.controller.clustering.services.CacheConfigException;
import org.opendaylight.controller.clustering.services.CacheExistException;
import org.opendaylight.controller.clustering.services.IClusterContainerServices;
nc,
Short.valueOf(vlan));
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
return new Status(StatusCode.BADREQUEST, "Invalid Address");
}
}
address = InetAddress.getByName(networkAddress);
return removeStaticHostReq(address);
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
return new Status(StatusCode.BADREQUEST, "Invalid Address");
}
}
this.listener.logged(entry);
}
}
+
+ /*
+ * Install the default exception handler so that the uncaught
+ * exceptions are handled by our customized handler. This new
+ * handler will display the exceptions to OSGI console as well
+ * as log to file.
+ */
+ Thread.setDefaultUncaughtExceptionHandler(new org.opendaylight.
+ controller.logging.bridge.internal.UncaughtExceptionHandler());
} else {
this.log.error("Cannot register the LogListener because "
+ "cannot retrive LogReaderService");
--- /dev/null
+package org.opendaylight.controller.logging.bridge.internal;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler{
+ private static Logger log = LoggerFactory.getLogger(UncaughtExceptionHandler.class);
+
+ public void uncaughtException (Thread t, Throwable e) {
+ log.error("Uncaught ExceptionHandler:", e);
+ }
+}
import org.opendaylight.controller.sal.core.State;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class TopologyTest {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(TopologyTest.class);
@Test
public void edgePropertiesTopologyTest() {
try {
e12 = new Edge(nc12, nc21);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
assertTrue(false);
}
try {
e23 = new Edge(nc23, nc32);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
assertTrue(false);
}
import org.eclipse.osgi.framework.console.CommandProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This java class provides the osgi console with the commands for running the unit test scripts for the API3
*
*/
public class API3UnitTest implements CommandProvider {
+ private static Logger log = LoggerFactory
+ .getLogger(API3UnitTest.class);
+
private static final String python = "/usr/bin/python";
/**
printStream(process.getErrorStream());
} catch (Exception e) {
System.out.println("Exception!");
- e.printStackTrace();
+ logger.error("",e);
}
}
printStream(process.getErrorStream());
} catch (Exception e) {
System.out.println("Exception!");
- e.printStackTrace();
+ logger.error("",e);
}
}
if (shuttingDown)
return;
} catch (Exception e2) {
- e2.printStackTrace();
+ logger.error("",e2);
}
}
}
import org.opendaylight.controller.sal.match.MatchType;
import org.opendaylight.controller.sal.utils.NetUtils;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility class for converting a SAL Flow into the OF flow and vice-versa
*/
public class FlowConverter {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(FlowConverter.class);
private Flow flow; // SAL Flow
private OFMatch ofMatch; // OF 1.0 match or OF 1.0 + IPv6 extension match
private List<OFAction> actionsList; // OF 1.0 actions
try {
ip = InetAddress.getByAddress(addr);
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
salAction = new SetNwSrc(ip);
} else if (ofAction instanceof OFActionNetworkLayerDestination) {
try {
ip = InetAddress.getByAddress(addr);
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
salAction = new SetNwDst(ip);
} else if (ofAction instanceof OFActionNetworkTypeOfService) {
return flow;
}
-}
\ No newline at end of file
+}
try {
node = new Node(NodeIDType.OPENFLOW, id);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return node;
handlePortStatusMessage(sw, (OFPortStatus) msg);
}
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return;
}
return;
}
} catch (Exception e2) {
- e2.printStackTrace();
+ logger.error("",e2);
}
}
}
return;
}
} catch (Exception e2) {
- e2.printStackTrace();
+ logger.error("",e2);
}
}
}
address = InetAddress.getByAddress(ByteBuffer.allocate(4)
.putInt(match.getNetworkSource()).array());
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
this.setNetworkSource(address, null);
} else {
address = InetAddress.getByAddress(ByteBuffer.allocate(4)
.putInt(match.getNetworkDestination()).array());
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
this.setNetworkDestination(address, null);
} else {
match_len += 20;
}
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
} else if (values[0].equals(STR_NW_SRC)
|| values[0].equals("ip_src")) {
match_len += 20;
}
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
} else if (values[0].equals(STR_NW_PROTO)) {
this.networkProtocol = U8.t(Short.valueOf(values[1]));
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.opendaylight</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ <relativePath>../../commons/opendaylight</relativePath>
+ </parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>protocol_plugins.stub</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.6</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package> org.opendaylight.controller.sal.packet,
+ org.opendaylight.controller.sal.action,
+ org.opendaylight.controller.sal.discovery,
+ org.opendaylight.controller.sal.topology,
+ org.opendaylight.controller.sal.core,
+ org.opendaylight.controller.sal.flowprogrammer,
+ org.opendaylight.controller.sal.reader,
+ org.opendaylight.controller.sal.inventory,
+ org.opendaylight.controller.sal.match,
+ org.opendaylight.controller.sal.utils,
+ org.apache.commons.lang3.builder,
+ org.apache.commons.lang3.tuple, org.apache.felix.dm,
+ org.slf4j, org.eclipse.osgi.framework.console,
+ org.osgi.framework
+ </Import-Package>
+ <Export-Package>
+ org.opendaylight.controller.protocol_plugins.stub.internal
+ </Export-Package>
+ <Bundle-Activator>
+ org.opendaylight.controller.protocol_plugins.stub.internal.Activator
+ </Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.protocol_plugins.stub.internal;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.Component;
+
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+import org.opendaylight.controller.sal.core.IContainerListener;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.discovery.IDiscoveryService;
+import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
+import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
+import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
+import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
+import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
+import org.opendaylight.controller.sal.reader.IPluginInReadService;
+import org.opendaylight.controller.sal.reader.IReadService;
+import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
+import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
+import org.opendaylight.controller.sal.utils.GlobalConstants;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * stub protocol plugin Activator
+ *
+ *
+ */
+public class Activator extends ComponentActivatorAbstractBase {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(Activator.class);
+
+ /**
+ * Function called when the activator starts just after some initializations
+ * are done by the ComponentActivatorAbstractBase.
+ *
+ */
+ public void init() {
+ }
+
+ /**
+ * Function called when the activator stops just before the cleanup done by
+ * ComponentActivatorAbstractBase
+ *
+ */
+ public void destroy() {
+ }
+
+ /**
+ * Function that is used to communicate to dependency manager the list of
+ * known implementations for services inside a container
+ *
+ *
+ * @return An array containing all the CLASS objects that will be
+ * instantiated in order to get an fully working implementation
+ * Object
+ */
+ public Object[] getImplementations() {
+ Object[] res = { ReadService.class };
+ return res;
+ }
+
+ /**
+ * Function that is called when configuration of the dependencies is
+ * required.
+ *
+ * @param c
+ * dependency manager Component object, used for configuring the
+ * dependencies exported and imported
+ * @param imp
+ * Implementation class that is being configured, needed as long
+ * as the same routine can configure multiple implementations
+ * @param containerName
+ * The containerName being configured, this allow also optional
+ * per-container different behavior if needed, usually should not
+ * be the case though.
+ */
+ public void configureInstance(Component c, Object imp, String containerName) {
+ if (imp.equals(ReadService.class)) {
+ // export the service to be used by SAL
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ // Set the protocolPluginType property which will be used
+ // by SAL
+ props.put("protocolPluginType", Node.NodeIDType.OPENFLOW);
+ c.setInterface(IPluginInReadService.class.getName(), props);
+ }
+ }
+
+}
--- /dev/null
+package org.opendaylight.controller.protocol_plugins.stub.internal;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.List;
+
+import org.apache.felix.dm.Component;
+//import org.opendaylight.controller.protocol_plugin_stubs.IPluginReadServiceFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.opendaylight.controller.sal.action.Action;
+import org.opendaylight.controller.sal.action.Drop;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.flowprogrammer.Flow;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.controller.sal.reader.FlowOnNode;
+import org.opendaylight.controller.sal.reader.IPluginInReadService;
+import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
+import org.opendaylight.controller.sal.reader.NodeDescription;
+
+/**
+ * Stub Implementation for IPluginInReadService used by SAL
+ *
+ *
+ */
+public class ReadService implements IPluginInReadService {
+ private static final Logger logger = LoggerFactory
+ .getLogger(ReadService.class);
+
+ /**
+ * Function called by the dependency manager when all the required
+ * dependencies are satisfied
+ *
+ */
+ void init() {
+ }
+
+ /**
+ * Function called by the dependency manager when at least one dependency
+ * become unsatisfied or when the component is shutting down because for
+ * example bundle is being stopped.
+ *
+ */
+ void destroy() {
+ }
+
+ /**
+ * Function called by dependency manager after "init ()" is called and after
+ * the services provided by the class are registered in the service registry
+ *
+ */
+ void start() {
+ }
+
+ /**
+ * Function called by the dependency manager before the services exported by
+ * the component are unregistered, this will be followed by a "destroy ()"
+ * calls
+ *
+ */
+ void stop() {
+ }
+
+ @Override
+ public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
+ FlowOnNode fn1 = new FlowOnNode(flow);
+ fn1.setByteCount(100);
+ fn1.setDurationNanoseconds(400);
+ fn1.setDurationSeconds(40);
+ fn1.setTableId((byte) 0x1);
+ fn1.setPacketCount(200);
+ return fn1;
+ }
+
+ @Override
+ public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
+ Flow flow = new Flow();
+
+ Match match = new Match();
+ try {
+ match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
+ } catch (UnknownHostException e) {
+
+ }
+ flow.setMatch(match);
+ Action action = new Drop();
+
+ List<Action> actions = new ArrayList<Action>();
+ actions.add(action);
+ flow.setActions(actions);
+
+ FlowOnNode fn1 = new FlowOnNode(flow);
+ fn1.setByteCount(100);
+ fn1.setDurationNanoseconds(400);
+ fn1.setDurationSeconds(40);
+ fn1.setTableId((byte) 0x1);
+ fn1.setPacketCount(200);
+
+ ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
+ list.add(fn1);
+ return list;
+ }
+
+ @Override
+ public NodeDescription readDescription(Node node, boolean cached) {
+ NodeDescription desc = new NodeDescription();
+ desc.setDescription("This is a sample node description");
+ desc.setHardware("stub hardware");
+ desc.setSoftware("stub software");
+ desc.setSerialNumber("123");
+ desc.setManufacturer("opendaylight");
+ return desc;
+ }
+
+ @Override
+ public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
+ boolean cached) {
+ NodeConnectorStatistics stats = new NodeConnectorStatistics();
+ stats.setNodeConnector(connector);
+ stats.setCollisionCount(4);
+ stats.setReceiveByteCount(1000);
+ stats.setReceiveCRCErrorCount(1);
+ stats.setReceiveDropCount(2);
+ stats.setReceiveErrorCount(3);
+ stats.setReceiveFrameErrorCount(5);
+ stats.setReceiveOverRunErrorCount(6);
+ stats.setReceivePacketCount(250);
+ stats.setTransmitByteCount(5000);
+ stats.setTransmitDropCount(50);
+ stats.setTransmitErrorCount(10);
+ stats.setTransmitPacketCount(500);
+
+ return stats;
+ }
+
+ @Override
+ public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
+ boolean cached) {
+ NodeConnector nc = NodeConnector.fromStringNoNode("123", node);
+ NodeConnectorStatistics stats = new NodeConnectorStatistics();
+ stats.setNodeConnector(nc);
+ stats.setCollisionCount(4);
+ stats.setReceiveByteCount(1000);
+ stats.setReceiveCRCErrorCount(1);
+ stats.setReceiveDropCount(2);
+ stats.setReceiveErrorCount(3);
+ stats.setReceiveFrameErrorCount(5);
+ stats.setReceiveOverRunErrorCount(6);
+ stats.setReceivePacketCount(250);
+ stats.setTransmitByteCount(5000);
+ stats.setTransmitDropCount(50);
+ stats.setTransmitErrorCount(10);
+ stats.setTransmitPacketCount(500);
+
+ List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
+ result.add(stats);
+ return result;
+ }
+
+ @Override
+ public long getTransmitRate(NodeConnector connector) {
+ return 100;
+ }
+
+}
.getNode(), dst
.getNode(), EdgeType.DIRECTED);
} catch (ConstructionException e) {
- e.printStackTrace();
+ log.error("",e);
return edgePresentInGraph;
}
}
try {
topo.removeEdge(new Edge(src, dst));
} catch (ConstructionException e) {
- e.printStackTrace();
+ log.error("",e);
return edgePresentInGraph;
}
import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.routing.dijkstra_implementation.internal.DijkstraImplementation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DijkstraTest {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(DijkstraTest.class);
@Test
public void testSinglePathRouteNoBw() {
DijkstraImplementation imp = new DijkstraImplementation();
try {
edge1 = new Edge(nc11, nc21);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
edge2 = new Edge(nc22, nc31);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props2 = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
expectedRes = new Path(expectedPath);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
if (!res.equals(expectedRes)) {
System.out.println("Actual Res is " + res);
try {
edge1 = new Edge(nc11, nc21);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
edge2 = new Edge(nc22, nc31);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props2 = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
edge3 = new Edge(nc12, nc32);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props3 = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
expectedRes = new Path(expectedPath);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
if (!res.equals(expectedRes)) {
System.out.println("Actual Res is " + res);
try {
edge1 = new Edge(nc11, nc21);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
edge2 = new Edge(nc22, nc31);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props2 = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
edge3 = new Edge(nc12, nc32);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Set<Property> props3 = new HashSet<Property>();
props.add(new Bandwidth(0));
try {
expectedRes = new Path(expectedPath);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
if (!res.equals(expectedRes)) {
System.out.println("Actual Res is " + res);
import org.opendaylight.controller.routing.dijkstra_implementation.internal.DijkstraImplementation;
import org.opendaylight.controller.sal.core.UpdateType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class MaxThruputTest {
-
+ protected static final Logger logger = LoggerFactory
+ .getLogger(MaxThruputTest.class);
Map<Edge, Number> LinkCostMap = new HashMap<Edge, Number>();
@Test
try {
edge1 = new Edge(nc11, nc21);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge1, 10);
Edge edge2 = null;
try {
edge2 = new Edge(nc21, nc11);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge2, 10);
try {
edge3 = new Edge(nc22, nc31);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge3, 30);
Edge edge4 = null;
try {
edge4 = new Edge(nc31, nc22);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge4, 30);
try {
edge5 = new Edge(nc32, nc41);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge5, 10);
Edge edge6 = null;
try {
edge6 = new Edge(nc41, nc32);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge6, 10);
try {
edge7 = new Edge(nc12, nc51);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge7, 20);
Edge edge8 = null;
try {
edge8 = new Edge(nc51, nc12);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge8, 20);
try {
edge9 = new Edge(nc52, nc61);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge9, 20);
Edge edge10 = null;
try {
edge10 = new Edge(nc61, nc52);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge10, 20);
try {
edge11 = new Edge(nc62, nc42);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge11, 20);
Edge edge12 = null;
try {
edge12 = new Edge(nc42, nc62);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
LinkCostMap.put(edge12, 20);
try {
expectedRes = new Path(expectedPath);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
if (!res.equals(expectedRes)) {
System.out.println("Actual Res is " + res);
try {
expectedRes = new Path(expectedPath);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
if (!res.equals(expectedRes)) {
System.out.println("Actual Res is " + res);
} catch (Exception e) {
logger.error(e.getMessage());
if (debug) {
- e.printStackTrace();
+ logger.error("",e);
}
}
}
import org.opendaylight.controller.sal.action.SetNwSrc;
import org.opendaylight.controller.sal.match.Match;
import org.opendaylight.controller.sal.utils.EtherTypes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Represent a flow: match + actions + flow specific properties
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class Flow implements Cloneable, Serializable {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(Flow.class);
private static final long serialVersionUID = 1L;
@XmlElement
private Match match;
try {
throw new Exception("Conflicting Match and Action list");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
} else {
this.match = match;
cloned.match = this.getMatch();
cloned.actions = this.getActions();
} catch (CloneNotSupportedException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return cloned;
}
}
}
} catch (CloneNotSupportedException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return cloned;
}
import java.util.Arrays;
import org.opendaylight.controller.sal.utils.NetUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* BitBufferHelper class that provides utility methods to
*
*/
public abstract class BitBufferHelper {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(BitBufferHelper.class);
public static long ByteMask = 0xFF;
throw new Exception(
"Container is too small for the number of requested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
return (data[0]);
throw new Exception(
"Container is too small for the number of requested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
return (short) toNumber(data);
throw new Exception(
"Container is too small for the number of requested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
return (int) toNumber(data);
throw new Exception(
"Container is too small for the number of requested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
return (long) toNumber(data);
throw new Exception(
"Container is too small for the number of requested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
throw new Exception(
"Container is too small for the number of requiested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
throw new Exception(
"Container is too small for the number of requested bits");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
if (numBits > data.length * NetUtils.NumBitsInAByte) {
throw new Exception(
"Trying to read more bits than contained in the data buffer");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
int startOffset = data.length * NetUtils.NumBitsInAByte - numBits;
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.sal.utils.IPProtocols;
import org.opendaylight.controller.sal.utils.NetUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Class that represents the IPv4 packet objects
*/
public class IPv4 extends Packet {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(IPv4.class);
private static final String VERSION = "Version";
private static final String HEADERLENGTH = "HeaderLength";
private static final String DIFFSERV = "DiffServ";
try {
payloadLength = payload.serialize().length;
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
}
this.setTotalLength((short) (this.getHeaderLen() + payloadLength));
}
import org.apache.commons.lang3.tuple.Pair;
import org.opendaylight.controller.sal.utils.HexEncode;
import org.opendaylight.controller.sal.utils.NetUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Abstract class which represents the generic network packet object
*/
public abstract class Packet {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(Packet.class);
// Access level granted to this packet
protected boolean writeAccess;
// When deserialized from wire, packet could result corrupted
.getHostAddress()
+ " ");
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
} else {
ret.append(((Long) BitBufferHelper.getLong(entry.getValue()))
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Utility class containing the common utility functions needed
* for operating on networking data structures
*
*/
public abstract class NetUtils {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(NetUtils.class);
/**
* Constant holding the number of bits in a byte
*/
try {
ip = InetAddress.getByAddress(NetUtils.intToByteArray4(address));
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return ip;
}
try {
return InetAddress.getByAddress(address);
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return null;
}
try {
address = InetAddress.getByName(addressString);
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
return address;
}
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Node.NodeIDType;
import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The class provides helper functions to create a node connector
*
*/
public abstract class NodeConnectorCreator {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(NodeConnectorCreator.class);
/**
* Generic NodeConnector creator
* The nodeConnector type is inferred from the node type
return new NodeConnector(NodeConnectorIDType.OPENFLOW,
(Short) portId, node);
} catch (ConstructionException e1) {
- e1.printStackTrace();
+ logger.error("",e1);
return null;
}
}
try {
return new NodeConnector(nodeConnectorType, portId, node);
} catch (ConstructionException e1) {
- e1.printStackTrace();
+ logger.error("",e1);
return null;
}
}
try {
return new NodeConnector(NodeConnectorIDType.OPENFLOW, portId, node);
} catch (ConstructionException e1) {
- e1.printStackTrace();
+ logger.error("",e1);
return null;
}
}
}
return nodeConnectors;
} catch (ConstructionException e1) {
- e1.printStackTrace();
+ logger.error("",e1);
return null;
}
}
import org.opendaylight.controller.sal.core.ConstructionException;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.core.Node.NodeIDType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility class for creating a Node object
*
*/
public abstract class NodeCreator {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(NodeCreator.class);
public static Node createOFNode(Long switchId) {
try {
return new Node(NodeIDType.OPENFLOW, switchId);
} catch (ConstructionException e1) {
- e1.printStackTrace();
+ logger.error("",e1);
return null;
}
}
import java.io.*;
import java.util.ArrayList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Convenience object to write a file
*
*
*/
public class WriteToFile {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(WriteToFile.class);
private FileWriter fstream;
private BufferedWriter bufferOut;
private String fileName;
try {
this.bufferOut.flush();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.utils.EtherTypes;
import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ActionTest {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(ActionTest.class);
@Test
public void tesActionCreationValidation() {
Action action = new PopVlan();
try {
ip = InetAddress.getByName("171.71.9.52");
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
action = new SetNwSrc(ip);
try {
ip = InetAddress.getByName("2001:420:281:1003:f2de:f1ff:fe71:728d");
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
action = new SetNwSrc(ip);
Assert.assertTrue(action.isValid());
try {
ip = InetAddress.getByName("1.1.1.1");
} catch (UnknownHostException e) {
- e.printStackTrace();
+ logger.error("",e);
}
actions.add(new SetDlSrc(mac));
try {
data = pkt.serialize();
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("",e);
return null;
}
if (data.length <= 0) {
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
ci.println(this.addFlow(node, getSampleFlow(node)));
}
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Flow flowA = getSampleFlow(node);
Flow flowB = getSampleFlow(node);
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
ci.println(this.removeFlow(node, getSampleFlow(node)));
}
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
ci.println(this.addFlow(node, getSampleFlowV6(node)));
}
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
ci.println(this.removeFlow(node, getSampleFlowV6(node)));
}
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
List<FlowOnNode> list = (cached) ? this.readAllFlows(node) : this
.nonCachedReadAllFlows(node);
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
Flow flow = getSampleFlow(node);
FlowOnNode flowOnNode = (cached) ? this.readFlow(node, flow) : this
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
List<NodeConnectorStatistics> list = (cached) ? this
.readNodeConnectors(node) : this
try {
node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
NodeDescription desc = (cached) ? this.readDescription(node) : this
.nonCachedReadDescription(node);
final List<ParseTree> trees = parseStreams(yangFiles);
final ModuleBuilder[] builders = new ModuleBuilder[trees.size()];
+ // validation\r
+ // if validation fails with any file, do not continue and throw\r
+ // exception\r
+ for (int i = 0; i < trees.size(); i++) {\r
+ try {\r
+ final YangModelValidationListener yangModelParser = new YangModelValidationListener();\r
+ walker.walk(yangModelParser, trees.get(i));\r
+ } catch (IllegalStateException e) {\r
+ // wrap exception to add information about which file failed\r
+ throw new YangValidationException(\r
+ "Yang validation failed for file" + yangFiles[i], e);\r
+ }\r
+ }\r
+
+
YangModelParserListenerImpl yangModelParser = null;
for (int i = 0; i < trees.size(); i++) {
yangModelParser = new YangModelParserListenerImpl();
private String yangModelPrefix;\r
private Date revision = new Date(0L);\r
\r
- private final DateFormat simpleDateFormat = new SimpleDateFormat(\r
+ final static DateFormat simpleDateFormat = new SimpleDateFormat(\r
"yyyy-mm-dd");\r
private final Stack<String> actualPath = new Stack<String>();\r
\r
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.model.parser.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Belongs_to_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Import_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Include_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_header_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Namespace_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_date_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_header_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener;
+import org.opendaylight.controller.yang.model.parser.util.YangModelBuilderUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Validation listener that validates yang statements according to RFC-6020.
+ * This validator expects only one module or submodule per file.
+ */
+
+/*
+ * TODO is this assumption(module per file) correct ? if so, should a check be
+ * performed ?
+ *
+ * TODO break into smaller classes e.g. class for header statements, body
+ * statements...
+ */
+final class YangModelValidationListener extends YangParserBaseListener {
+
+ private static final Logger logger = LoggerFactory
+ .getLogger(YangModelValidationListener.class);
+
+ private final Set<String> uniquePrefixes;
+ private final Set<String> uniqueImports;
+ private final Set<String> uniqueIncludes;
+
+ public YangModelValidationListener() {
+ super();
+ uniquePrefixes = new HashSet<String>();
+ uniqueImports = new HashSet<String>();
+ uniqueIncludes = new HashSet<String>();
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Identifier contains only permitted characters</li>
+ * <li>One revision statements present</li>
+ * <li>One header statements present</li>
+ * </ol>
+ */
+ @Override
+ public void enterModule_stmt(YangParser.Module_stmtContext ctx) {
+ String moduleName = getName(ctx);
+
+ checkIdentifier(moduleName, "Module");
+
+ checkPresentChildOfType(ctx, Revision_stmtsContext.class,
+ f("Missing revision statements in module:%s", moduleName), true);
+
+ checkPresentChildOfType(ctx, Module_header_stmtsContext.class,
+ f("Missing header statements in module:%s", moduleName), true);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Identifier contains only permitted characters</li>
+ * <li>One revision statements present</li>
+ * <li>One header statements present</li>
+ * </ol>
+ */
+ @Override
+ public void enterSubmodule_stmt(Submodule_stmtContext ctx) {
+ String submoduleName = getName(ctx);
+
+ checkIdentifier(submoduleName, "Submodule");
+
+ checkPresentChildOfType(
+ ctx,
+ Revision_stmtsContext.class,
+ f("Missing revision statements in submodule:%s", submoduleName),
+ true);
+
+ checkPresentChildOfType(ctx, Submodule_header_stmtsContext.class,
+ f("Missing header statements in submodule:%s", submoduleName),
+ true);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>One Belongs-to statement present</li>
+ * </ol>
+ */
+ @Override
+ public void enterSubmodule_header_stmts(Submodule_header_stmtsContext ctx) {
+ String submoduleName = getRootParentName(ctx);
+
+ checkPresentChildOfType(
+ ctx,
+ Belongs_to_stmtContext.class,
+ f("Missing belongs-to statement in submodule:%s", submoduleName),
+ true);
+
+ // check Yang version present, if not issue warning
+ checkYangVersion(ctx, submoduleName);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Identifier contains only permitted characters</li>
+ * <li>One Prefix statement child</li>
+ * </ol>
+ */
+ @Override
+ public void enterBelongs_to_stmt(Belongs_to_stmtContext ctx) {
+ String belongToName = getName(ctx);
+ String rootParentName = getRootParentName(ctx);
+
+ checkIdentifier(belongToName,
+ f("In (sub)module:%s , Belongs-to statement", rootParentName));
+
+ checkPresentChildOfType(
+ ctx,
+ Prefix_stmtContext.class,
+ f("Missing prefix statement in belongs-to:%s, in (sub)module:%s",
+ belongToName, rootParentName), true);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>At least one Revision statement present</li>
+ * </ol>
+ */
+ @Override
+ public void enterRevision_stmts(Revision_stmtsContext ctx) {
+ String rootParentName = getRootParentName(ctx);
+
+ checkPresentChildOfType(
+ ctx,
+ Revision_stmtContext.class,
+ f("Missing at least one revision statement in (sub)module:%s",
+ rootParentName), false);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>One Namespace statement present</li>
+ * </ol>
+ */
+ @Override
+ public void enterModule_header_stmts(Module_header_stmtsContext ctx) {
+ String moduleName = getRootParentName(ctx);
+
+ checkPresentChildOfType(ctx, Namespace_stmtContext.class,
+ f("Missing namespace statement in module:%s", moduleName), true);
+
+ // check Yang version present, if not issue warning
+ checkYangVersion(ctx, moduleName);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Namespace string can be parsed as URI</li>
+ * </ol>
+ */
+ @Override
+ public void enterNamespace_stmt(Namespace_stmtContext ctx) {
+ String namespaceName = getName(ctx);
+ String rootParentName = getRootParentName(ctx);
+
+ try {
+ new URI(namespaceName);
+ } catch (URISyntaxException e) {
+ throw new YangValidationException(f(
+ "Namespace:%s in module:%s cannot be parsed as URI",
+ namespaceName, rootParentName));
+ }
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Identifier contains only permitted characters</li>
+ * <li>Every import(identified by identifier) within a module/submodule is
+ * present only once</li>
+ * <li>One prefix statement child</li>
+ * <li>One revision-date statement child</li>
+ * </ol>
+ */
+ @Override
+ public void enterImport_stmt(Import_stmtContext ctx) {
+ String importName = getName(ctx);
+ String rootParentName = getRootParentName(ctx);
+
+ checkIdentifier(importName,
+ f("In (sub)module:%s , Import statement", rootParentName));
+
+ if (uniqueImports.contains(importName))
+ throw new YangValidationException(f(
+ "Module:%s imported twice in (sub)module:%s", importName,
+ rootParentName));
+ uniqueImports.add(importName);
+
+ checkPresentChildOfType(
+ ctx,
+ Prefix_stmtContext.class,
+ f("Missing prefix statement in import:%s, in (sub)module:%s",
+ importName, rootParentName), true);
+ checkPresentChildOfType(
+ ctx,
+ Revision_date_stmtContext.class,
+ f("Missing revision-date statement in import:%s, in (sub)module:%s",
+ importName, rootParentName), true);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Date is in valid format</li>
+ * </ol>
+ */
+ @Override
+ public void enterRevision_date_stmt(Revision_date_stmtContext ctx) {
+ String rootParentName = getRootParentName(ctx);
+ String exceptionMessage = f(
+ "Invalid date format for revision-date:%s in import/include statement:%s, in (sub)module:%s , expected date format is:%s",
+ getName(ctx), getRootParentName(ctx), rootParentName,
+ YangModelParserListenerImpl.simpleDateFormat.format(new Date()));
+
+ validateDateFormat(getName(ctx),
+ YangModelParserListenerImpl.simpleDateFormat, exceptionMessage);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Identifier contains only permitted characters</li>
+ * <li>Every include(identified by identifier) within a module/submodule is
+ * present only once</li>
+ * <li>One Revision-date statement child</li>
+ * </ol>
+ */
+ @Override
+ public void enterInclude_stmt(Include_stmtContext ctx) {
+ String includeName = getName(ctx);
+ String rootParentName = getRootParentName(ctx);
+
+ checkIdentifier(includeName,
+ f("In (sub)module:%s , Include statement", rootParentName));
+
+ if (uniqueIncludes.contains(includeName))
+ throw new YangValidationException(f(
+ "Submodule:%s included twice in (sub)module:%s",
+ includeName, rootParentName));
+ uniqueIncludes.add(includeName);
+
+ checkPresentChildOfType(
+ ctx,
+ Revision_date_stmtContext.class,
+ f("Missing revision-date statement in include:%s, in (sub)module:%s",
+ includeName, rootParentName), true);
+ }
+
+ static final String SUPPORTED_YANG_VERSION = "1";
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Yang-version is specified as 1</li>
+ * </ol>
+ */
+ @Override
+ public void enterYang_version_stmt(YangParser.Yang_version_stmtContext ctx) {
+ String version = getName(ctx);
+ String rootParentName = getRootParentName(ctx);
+ if (!version.equals(SUPPORTED_YANG_VERSION)) {
+ throw new YangValidationException(
+ f("Unsupported yang version:%s, in (sub)module:%s, supported version:%s",
+ version, rootParentName, SUPPORTED_YANG_VERSION));
+ }
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Date is in valid format</li>
+ * </ol>
+ */
+ @Override
+ public void enterRevision_stmt(YangParser.Revision_stmtContext ctx) {
+ String parentName = getRootParentName(ctx);
+ String exceptionMessage = f(
+ "Invalid date format for revision:%s in (sub)module:%s, expected date format is:%s",
+ getName(ctx), parentName,
+ YangModelParserListenerImpl.simpleDateFormat.format(new Date()));
+
+ validateDateFormat(getName(ctx),
+ YangModelParserListenerImpl.simpleDateFormat, exceptionMessage);
+ }
+
+ /**
+ * Rules:
+ * <ol>
+ * <li>Identifier contains only permitted characters</li>
+ * <li>Every prefix(identified by identifier) within a module/submodule is
+ * presented only once</li>
+ * </ol>
+ */
+ @Override
+ public void enterPrefix_stmt(Prefix_stmtContext ctx) {
+ String name = getName(ctx);
+ checkIdentifier(
+ name,
+ f("In module or import statement:%s , Prefix",
+ getRootParentName(ctx)));
+
+ if (uniquePrefixes.contains(name))
+ throw new YangValidationException(f(
+ "Not a unique prefix:%s, in (sub)module:%s", name,
+ getRootParentName(ctx)));
+ uniquePrefixes.add(name);
+ }
+
+ private String getRootParentName(ParseTree ctx) {
+ ParseTree root = ctx;
+ while (root.getParent() != null) {
+ root = root.getParent();
+ }
+ return getName(root);
+ }
+
+ private static String getName(ParseTree child) {
+ return YangModelBuilderUtil.stringFromNode(child);
+ }
+
+ private static String f(String base, Object... args) {
+ return String.format(base, args);
+ }
+
+ private static void checkYangVersion(ParseTree ctx, String moduleName) {
+ if (!checkPresentChildOfType(ctx, Yang_version_stmtContext.class, true))
+ logger.warn(f(
+ "Yang version statement not present in module:%s, Validating as yang version:%s",
+ moduleName, SUPPORTED_YANG_VERSION));
+ }
+
+ private static void validateDateFormat(String string, DateFormat format,
+ String message) {
+ try {
+ format.parse(string);
+ } catch (ParseException e) {
+ throw new YangValidationException(message);
+ }
+ }
+
+ private static Pattern identifierPattern = Pattern
+ .compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
+
+ static void checkIdentifier(String name, String messagePrefix) {
+ if (!identifierPattern.matcher(name).matches())
+ throw new YangValidationException(f(
+ "%s identifier:%s is not in required format:%s",
+ messagePrefix, name, identifierPattern.toString()));
+ }
+
+ private static void checkPresentChildOfType(ParseTree ctx,
+ Class<?> expectedChildType, String message, boolean atMostOne) {
+ if (!checkPresentChildOfType(ctx, expectedChildType, atMostOne))
+ throw new YangValidationException(message);
+ }
+
+ private static boolean checkPresentChildOfType(ParseTree ctx,
+ Class<?> expectedChildType, boolean atMostOne) {
+
+ int count = 0;
+
+ for (int i = 0; i < ctx.getChildCount(); i++) {
+ ParseTree child = ctx.getChild(i);
+ if (expectedChildType.isInstance(child))
+ count++;
+ }
+
+ return atMostOne ? count == 1 ? true : false : count != 0 ? true
+ : false;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.model.parser.impl;
+
+/**
+ * Unchecked exception thrown if yang definition is not valid according to
+ * {@link YangModelValidationListener}
+ */
+public class YangValidationException extends RuntimeException {
+
+ private static final long serialVersionUID = 7414330400390825381L;
+
+ public YangValidationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public YangValidationException(String message) {
+ super(message);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.yang.model.parser.impl;
+
+import static org.hamcrest.core.Is.*;
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+import static org.mockito.Mockito.*;
+
+import java.util.Date;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Import_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Include_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_header_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Namespace_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_date_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.StringContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext;
+
+public class YangModelValidationListenerTest_Module {
+
+ private YangModelValidationListener valid;
+ private Module_stmtContext ctx;
+
+ @Before
+ public void setUp() {
+ valid = new YangModelValidationListener();
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testRevisionInvalidDateFormat() {
+ Revision_stmtContext mockedRev = mockModuleWithRevision(2, "badFormat");
+
+ try {
+ valid.enterRevision_stmt(mockedRev);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Invalid date format for revision:badFormat in (sub)module:module1, expected date format is:"));
+ throw e;
+ }
+ }
+
+ private Revision_stmtContext mockModuleWithRevision(int moduleChildren,
+ String date) {
+ Revision_stmtContext mockedRev = mock(Revision_stmtContext.class);
+ doReturn(1).when(mockedRev).getChildCount();
+ mockName(mockedRev, date);
+
+ Revision_stmtsContext revs = mockRevisionsParent(2, mockedRev);
+
+ mockModuleParent(moduleChildren, revs, "module1");
+ return mockedRev;
+ }
+
+ @Test
+ public void testRevisionValidDateFormat() {
+ Revision_stmtContext mockedRev = mockModuleWithRevision(2,
+ getFormattedDate());
+
+ valid.enterRevision_stmt(mockedRev);
+ }
+
+ private String getFormattedDate() {
+ return YangModelParserListenerImpl.simpleDateFormat.format(new Date());
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testNoRevision() {
+
+ Module_stmtContext ctx = mock(Module_stmtContext.class);
+ doReturn(1).when(ctx).getChildCount();
+ mockName(ctx, "module1");
+
+ try {
+ valid.enterModule_stmt(ctx);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing revision statements in module:module1"));
+ throw e;
+ }
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testNoHeaderStmts() {
+ mockModuleWithRevision(2, "1999-4-5");
+
+ try {
+ valid.enterModule_stmt(ctx);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing header statements in module:module1"));
+ throw e;
+ }
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testNoNamespace() {
+ Module_header_stmtsContext header = mock(Module_header_stmtsContext.class);
+ mockModuleParent(2, header, "module1");
+
+ try {
+ valid.enterModule_header_stmts(header);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing namespace statement in module:module1"));
+ throw e;
+ }
+ }
+
+ @Test
+ public void testPrefixes() {
+ Prefix_stmtContext pref = mock(Prefix_stmtContext.class);
+ doReturn(1).when(pref).getChildCount();
+ mockName(pref, "unique1");
+ mockModuleParent(2, pref, "module1");
+ valid.enterPrefix_stmt(pref);
+
+ pref = mock(Prefix_stmtContext.class);
+ doReturn(1).when(pref).getChildCount();
+ mockName(pref, "unique1");
+ mockModuleParent(2, pref, "module1");
+
+ try {
+ valid.enterPrefix_stmt(pref);
+ } catch (Exception e) {
+ return;
+ }
+
+ fail("Validation Exception should have occured");
+ }
+
+ @Test
+ public void testNamespace() {
+ Namespace_stmtContext namespace = mock(Namespace_stmtContext.class);
+ doReturn(1).when(namespace).getChildCount();
+ mockName(namespace, "http://test.parsing.uri.com");
+ mockModuleParent(2, namespace, "module1");
+ valid.enterNamespace_stmt(namespace);
+
+ namespace = mock(Namespace_stmtContext.class);
+ doReturn(1).when(namespace).getChildCount();
+ mockName(namespace, "invalid uri");
+ mockModuleParent(2, namespace, "module1");
+ try {
+ valid.enterNamespace_stmt(namespace);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Namespace:invalid uri in module:module1 cannot be parsed as URI"));
+ return;
+ }
+
+ fail("Validation Exception should have occured");
+ }
+
+ @Test
+ public void testImports() {
+ Import_stmtContext impor = mockImport("unique1", "p1");
+ mockModuleParent(2, impor, "module1");
+ valid.enterImport_stmt(impor);
+
+ impor = mockImport("unique1", "p2");
+ mockModuleParent(2, impor, "module1");
+ mockName(impor, "unique1");
+
+ try {
+ valid.enterImport_stmt(impor);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Module:unique1 imported twice in (sub)module:module1"));
+ return;
+ }
+
+ fail("Validation Exception should have occured");
+ }
+
+ @Test
+ public void testIncludes() {
+ Include_stmtContext impor = mockInclude("unique1");
+ mockModuleParent(2, impor, "module1");
+ valid.enterInclude_stmt(impor);
+
+ impor = mockInclude("unique1");
+ mockModuleParent(2, impor, "module1");
+ mockName(impor, "unique1");
+
+ try {
+ valid.enterInclude_stmt(impor);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Submodule:unique1 included twice in (sub)module:module1"));
+ return;
+ }
+
+ fail("Validation Exception should have occured");
+ }
+
+ private Import_stmtContext mockImport(String name, String prefixName) {
+ Import_stmtContext impor = mock(Import_stmtContext.class);
+ doReturn(3).when(impor).getChildCount();
+ Prefix_stmtContext prefix = mock(Prefix_stmtContext.class);
+ mockName(prefix, prefixName);
+ doReturn(prefix).when(impor).getChild(1);
+ Revision_date_stmtContext revDate = mock(Revision_date_stmtContext.class);
+ mockName(revDate, getFormattedDate());
+ doReturn(revDate).when(impor).getChild(2);
+ mockName(impor, name);
+ return impor;
+ }
+
+ private Include_stmtContext mockInclude(String name) {
+ Include_stmtContext impor = mock(Include_stmtContext.class);
+ doReturn(2).when(impor).getChildCount();
+ Revision_date_stmtContext revDate = mock(Revision_date_stmtContext.class);
+ mockName(revDate, getFormattedDate());
+ doReturn(revDate).when(impor).getChild(1);
+ mockName(impor, name);
+ return impor;
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testInvalidYangVersion() {
+
+ Yang_version_stmtContext yangVersion = mock(Yang_version_stmtContext.class);
+ doReturn(1).when(yangVersion).getChildCount();
+ mockName(yangVersion, "55Unsup");
+
+ mockModuleParent(2, yangVersion, "module1");
+
+ try {
+ valid.enterYang_version_stmt(yangVersion);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Unsupported yang version:55Unsup, in (sub)module:module1, supported version:"
+ + YangModelValidationListener.SUPPORTED_YANG_VERSION));
+ throw e;
+ }
+ }
+
+ private void mockModuleParent(int moduleChildren, ParseTree child,
+ String moduleName) {
+ ctx = mock(Module_stmtContext.class);
+ doReturn(moduleChildren).when(ctx).getChildCount();
+ mockName(ctx, moduleName);
+ doReturn(child).when(ctx).getChild(1);
+ doReturn(ctx).when(child).getParent();
+ }
+
+ static Revision_stmtsContext mockRevisionsParent(int moduleChildren,
+ Revision_stmtContext mockedRev) {
+ Revision_stmtsContext revs = mock(Revision_stmtsContext.class);
+ doReturn(moduleChildren).when(revs).getChildCount();
+ doReturn(mockedRev).when(revs).getChild(1);
+ doReturn(revs).when(mockedRev).getParent();
+ return revs;
+ }
+
+ @Test
+ public void testValidYangVersion() {
+
+ Yang_version_stmtContext ctx = mock(Yang_version_stmtContext.class);
+ doReturn(1).when(ctx).getChildCount();
+ mockName(ctx, "1");
+
+ valid.enterYang_version_stmt(ctx);
+ }
+
+ @Test
+ public void testIdentifierMatching() {
+ YangModelValidationListener.checkIdentifier("_ok98-.87.-.8...88-asdAD",
+ null);
+ YangModelValidationListener.checkIdentifier("AA.bcd", null);
+ YangModelValidationListener.checkIdentifier("a", null);
+
+ int thrown = 0;
+
+ try {
+ YangModelValidationListener.checkIdentifier("9aa", null);
+ } catch (YangValidationException e) {
+ thrown++;
+ }
+ try {
+ YangModelValidationListener.checkIdentifier("-", null);
+ } catch (YangValidationException e) {
+ thrown++;
+ }
+ try {
+ YangModelValidationListener.checkIdentifier(".", null);
+ } catch (YangValidationException e) {
+ thrown++;
+ }
+
+ assertThat(thrown, is(3));
+ }
+
+ static void mockName(ParseTree mockedRev, String name) {
+ StringContext nameCtx = mock(StringContext.class);
+ ParseTree internalName = mock(ParseTree.class);
+ doReturn(name).when(internalName).getText();
+ doReturn(internalName).when(nameCtx).getChild(0);
+ doReturn(nameCtx).when(mockedRev).getChild(0);
+ }
+}
--- /dev/null
+package org.opendaylight.controller.yang.model.parser.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+import static org.mockito.Mockito.*;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Belongs_to_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Prefix_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Revision_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_header_stmtsContext;
+import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_stmtContext;
+
+public class YangModelValidationListenerTest_SubModule {
+
+ private YangModelValidationListener valid;
+ private Submodule_stmtContext ctx;
+
+ @Before
+ public void setUp() {
+ valid = new YangModelValidationListener();
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testNoRevision() {
+
+ Submodule_stmtContext ctx = mock(Submodule_stmtContext.class);
+ doReturn(1).when(ctx).getChildCount();
+ YangModelValidationListenerTest_Module.mockName(ctx, "submodule1");
+
+ try {
+ valid.enterSubmodule_stmt(ctx);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing revision statements in submodule:submodule1"));
+ throw e;
+ }
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testNoHeaderStmts() {
+ mockSubmoduleWithRevision(2, "1999-4-5", "submodule");
+
+ try {
+ valid.enterSubmodule_stmt(ctx);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing header statements in submodule:submodule"));
+ throw e;
+ }
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testNoBelongsTo() {
+ Submodule_header_stmtsContext header = mock(Submodule_header_stmtsContext.class);
+ mockSubmoduleParent(2, header, "submodule");
+
+ try {
+ valid.enterSubmodule_header_stmts(header);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing belongs-to statement in submodule:submodule"));
+ throw e;
+ }
+ }
+
+ @Test(expected = YangValidationException.class)
+ public void testBelongsToNoPrefix() {
+ Belongs_to_stmtContext belongsTo = mock(Belongs_to_stmtContext.class);
+ doReturn(1).when(belongsTo).getChildCount();
+ YangModelValidationListenerTest_Module.mockName(belongsTo,
+ "supermodule");
+
+ mockSubmoduleParent(2, belongsTo, "submodule");
+
+ try {
+ valid.enterBelongs_to_stmt(belongsTo);
+ } catch (YangValidationException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Missing prefix statement in belongs-to:supermodule, in (sub)module:submodule"));
+ throw e;
+ }
+ }
+
+ @Test
+ public void testBelongsTo() {
+ Belongs_to_stmtContext belongsTo = mock(Belongs_to_stmtContext.class);
+ doReturn(2).when(belongsTo).getChildCount();
+ YangModelValidationListenerTest_Module.mockName(belongsTo,
+ "supermodule");
+
+ Prefix_stmtContext prefix = mock(Prefix_stmtContext.class);
+ doReturn(prefix).when(belongsTo).getChild(1);
+ doReturn(belongsTo).when(prefix).getParent();
+
+ mockSubmoduleParent(2, belongsTo, "submodule");
+ valid.enterBelongs_to_stmt(belongsTo);
+
+ }
+
+ private Revision_stmtContext mockSubmoduleWithRevision(int moduleChildren,
+ String date, String nameOfSubmodule) {
+ Revision_stmtContext mockedRev = mock(Revision_stmtContext.class);
+ doReturn(1).when(mockedRev).getChildCount();
+ YangModelValidationListenerTest_Module.mockName(mockedRev, date);
+
+ Revision_stmtsContext revs = YangModelValidationListenerTest_Module
+ .mockRevisionsParent(2, mockedRev);
+
+ mockSubmoduleParent(moduleChildren, revs, nameOfSubmodule);
+ return mockedRev;
+ }
+
+ private void mockSubmoduleParent(int moduleChildren, ParseTree child,
+ String moduleName) {
+ ctx = mock(Submodule_stmtContext.class);
+ doReturn(moduleChildren).when(ctx).getChildCount();
+ YangModelValidationListenerTest_Module.mockName(ctx, moduleName);
+ doReturn(child).when(ctx).getChild(1);
+ doReturn(ctx).when(child).getParent();
+ }
+}
prefix "iit";
organization "opendaylight";
+ revision 2012-04-16 {
+ }
contact "WILL-BE-DEFINED-LATER";
import org.opendaylight.controller.sal.core.impl.NotificationModule;\r
\r
\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
public class SALDemo {\r
+ protected static final Logger logger = LoggerFactory\r
+ .getLogger(SALDemo.class);\r
\r
static BrokerImpl broker;\r
static DemoProviderImpl provider;\r
}\r
} catch (IOException e) {\r
\r
- e.printStackTrace();\r
+ logger.error("",e);\r
}\r
}\r
\r
import java.text.SimpleDateFormat;\r
import java.util.Date;\r
\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
/**\r
* The QName from XML consists of local name of element and XML namespace, but\r
* for our use, we added module revision to it.\r
* \r
*/\r
public class QName {\r
+ protected static final Logger logger = LoggerFactory\r
+ .getLogger(QName.class);\r
\r
private SimpleDateFormat revisionFormat = new SimpleDateFormat("yyyy-MM-dd");\r
\r
namespace.getPort(), namespace.getPath(), query,\r
namespace.getFragment());\r
} catch (URISyntaxException e) {\r
- e.printStackTrace();\r
+ logger.error("",e);\r
}\r
return compositeURI;\r
}\r
}
}catch (UnknownHostException e) {
lbsLogger.error("Pool member not found in the network : {}",e.getMessage());
- e.printStackTrace();
+ lbsLogger.error("",e);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.controller</groupId>
<artifactId>commons.opendaylight</artifactId>
<version>1.4.0-SNAPSHOT</version>
- <relativePath>../commons/opendaylight</relativePath>
+ <relativePath>../../commons/opendaylight</relativePath>
</parent>
-
<groupId>org.opendaylight.controller</groupId>
<artifactId>statisticsmanager</artifactId>
<version>0.4.0-SNAPSHOT</version>
<packaging>bundle</packaging>
-
<build>
<plugins>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.6</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Import-Package>
- org.opendaylight.controller.forwardingrulesmanager,
- org.opendaylight.controller.containermanager,
- org.opendaylight.controller.sal.core,
- org.opendaylight.controller.sal.flowprogrammer,
- org.slf4j,
- org.opendaylight.controller.sal.reader,
- org.apache.felix.dm
- </Import-Package>
- <Bundle-Activator>
- org.opendaylight.controller.statisticsmanager.internal.Activator
- </Bundle-Activator>
- <Export-Package>
- org.opendaylight.controller.statisticsmanager
- </Export-Package>
- </instructions>
- </configuration>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.6</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.opendaylight.controller.forwardingrulesmanager,
+ org.opendaylight.controller.containermanager,
+ org.opendaylight.controller.sal.core,
+ org.opendaylight.controller.sal.flowprogrammer, org.slf4j,
+ org.opendaylight.controller.sal.reader,
+ org.apache.felix.dm
+ </Import-Package>
+ <Export-Package>
+ org.opendaylight.controller.statisticsmanager
+ </Export-Package>
+ </instructions>
+ </configuration>
</plugin>
</plugins>
</build>
<artifactId>forwardingrulesmanager</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>clustering.services</artifactId>
<version>0.4.0-SNAPSHOT</version>
</dependency>
</dependencies>
-</project>
+</project>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.opendaylight</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ <relativePath>../../commons/opendaylight</relativePath>
+ </parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>statisticsmanager.implementation</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <properties>
+ <!-- Sonar properties using jacoco to retrieve integration test results -->
+ <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
+ <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
+ <sonar.jacoco.Reportpath>target/jacobo.exec</sonar.jacoco.Reportpath>
+ <sonar.jacoco.itReportPath>target/jacoco-it.exec</sonar.jacoco.itReportPath>
+ <sonar.language>java</sonar.language>
+ </properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.5.3.201107060350</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.6</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.opendaylight.controller.containermanager,
+ org.opendaylight.controller.sal.core,
+ org.opendaylight.controller.sal.flowprogrammer, org.slf4j,
+ org.opendaylight.controller.sal.reader,
+ org.opendaylight.controller.statisticsmanager,
+ org.opendaylight.controller.forwardingrulesmanager,
+ org.apache.felix.dm
+ </Import-Package>
+ <Bundle-Activator>
+ org.opendaylight.controller.statisticsmanager.internal.Activator
+ </Bundle-Activator>
+ <Export-Package>
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <configuration>
+ <includes>org.opendaylight.controller.*</includes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>pre-test</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>post-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>statisticsmanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>containermanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>forwardingrulesmanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>clustering.services</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
import org.opendaylight.controller.sal.reader.IReadService;
import org.opendaylight.controller.statisticsmanager.IStatisticsManager;
-import org.opendaylight.controller.statisticsmanager.StatisticsManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.controller.statisticsmanager;
+package org.opendaylight.controller.statisticsmanager.internal;
import java.util.ArrayList;
import java.util.HashMap;
import org.opendaylight.controller.sal.reader.IReadService;
import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
import org.opendaylight.controller.sal.reader.NodeDescription;
+import org.opendaylight.controller.statisticsmanager.IStatisticsManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-\r
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.controller.statisticsmanager;\r
-\r
-import org.junit.Test;\r
-\r
-public class StatisticsManagerTest {\r
-\r
- @Test\r
- public void test() {\r
- StatisticsManager sm = new StatisticsManager();\r
- \r
- sm.init();\r
- sm.start();\r
- sm.stop();\r
- sm.destroy();\r
- \r
- \r
- }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.statisticsmanager.internal;
+
+import org.junit.Test;
+import org.opendaylight.controller.statisticsmanager.internal.StatisticsManager;
+
+public class StatisticsManagerTest {
+
+ @Test
+ public void test() {
+ StatisticsManager sm = new StatisticsManager();
+
+ sm.init();
+ sm.start();
+ sm.stop();
+ sm.destroy();
+
+ }
+
+}
--- /dev/null
+<configuration scan="true">
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+ </pattern>
+ </encoder>
+ </appender>
+
+ <root level="error">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.opendaylight</artifactId>
+ <version>1.4.0-SNAPSHOT</version>
+ <relativePath>../../commons/opendaylight</relativePath>
+ </parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>statisticsmanager.integrationtest</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>protocol_plugins.stub</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal.implementation</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>containermanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>forwardingrulesmanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>clustering.services</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>statisticsmanager</artifactId>
+ <version>0.4.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <!-- Sonar jacoco plugin to get integration test coverage info -->
+ <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
+ <sonar.jacoco.reportPath>../implementation/target/jacoco.exec</sonar.jacoco.reportPath>
+ <sonar.jacoco.itReportPath>../implementaiton/target/jacoco-it.exec</sonar.jacoco.itReportPath>
+ <sonar.language>java</sonar.language>
+ </properties>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.5.3.201107060350</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.5.3.201107060350</version>
+ <configuration>
+ <destFile>../implementation/target/jacoco-it.exec</destFile>
+ <includes>org.opendaylight.controller.*</includes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>pre-test</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>post-test</id>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.statisticsmanager.internal;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Bundle;
+import javax.inject.Inject;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
+import org.opendaylight.controller.sal.action.Action;
+import org.opendaylight.controller.sal.action.Drop;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.flowprogrammer.Flow;
+import org.opendaylight.controller.sal.match.Match;
+import org.opendaylight.controller.sal.match.MatchType;
+import org.opendaylight.controller.sal.reader.FlowOnNode;
+import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
+import org.opendaylight.controller.sal.reader.NodeDescription;
+import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.statisticsmanager.*;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import static org.junit.Assert.*;
+import org.ops4j.pax.exam.junit.Configuration;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.util.PathUtils;
+
+@RunWith(PaxExam.class)
+public class StatisticsManagerIntegrationTest {
+ private Logger log = LoggerFactory
+ .getLogger(StatisticsManagerIntegrationTest.class);
+ // get the OSGI bundle context
+ @Inject
+ private BundleContext bc;
+
+ private IStatisticsManager manager = null;
+
+ // Configure the OSGi container
+ @Configuration
+ public Option[] config() {
+ return options(
+ //
+ systemProperty("logback.configurationFile").value(
+ "file:" + PathUtils.getBaseDir()
+ + "/src/test/resources/logback.xml"),
+ // To start OSGi console for inspection remotely
+ systemProperty("osgi.console").value("2401"),
+ // Set the systemPackages (used by clustering)
+ systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
+ // List framework bundles
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.console",
+ "1.0.0.v20120522-1841"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.util",
+ "1.0.400.v20120522-2049"),
+ mavenBundle("equinoxSDK381", "org.eclipse.osgi.services",
+ "3.3.100.v20120522-1822"),
+ mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds",
+ "1.4.0.v20120522-1841"),
+ mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command",
+ "0.8.0.v201108120515"),
+ mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime",
+ "0.8.0.v201108120515"),
+ mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell",
+ "0.8.0.v201110170705"),
+ // List logger bundles
+ mavenBundle("org.slf4j", "slf4j-api", "1.7.2"),
+ mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.2"),
+ mavenBundle("ch.qos.logback", "logback-core", "1.0.9"),
+ mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"),
+ // List all the bundles on which the test case depends
+ mavenBundle("org.opendaylight.controller", "sal",
+ "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller",
+ "sal.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "statisticsmanager",
+ "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation",
+ "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller",
+ "protocol_plugins.stub", "0.4.0-SNAPSHOT"),
+ // needed by statisticsmanager
+ mavenBundle("org.opendaylight.controller", "containermanager",
+ "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller",
+ "containermanager.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller",
+ "forwardingrulesmanager", "0.4.0-SNAPSHOT"),
+
+ mavenBundle("org.opendaylight.controller",
+ "clustering.services", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller",
+ "clustering.services-implementation", "0.4.0-SNAPSHOT"),
+
+ // needed by forwardingrulesmanager
+ mavenBundle("org.opendaylight.controller", "switchmanager",
+ "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "configuration",
+ "0.4.0-SNAPSHOT"),
+
+ mavenBundle("org.opendaylight.controller",
+ "configuration.implementation", "0.4.0-SNAPSHOT"),
+ mavenBundle("org.opendaylight.controller", "hosttracker",
+ "0.4.0-SNAPSHOT"),
+
+ // needed by hosttracker
+ mavenBundle("org.opendaylight.controller", "topologymanager",
+ "0.4.0-SNAPSHOT"),
+
+ mavenBundle("org.jboss.spec.javax.transaction",
+ "jboss-transaction-api_1.1_spec", "1.0.1.Final"),
+ mavenBundle("org.apache.commons", "commons-lang3", "3.1"),
+ mavenBundle("org.apache.felix",
+ "org.apache.felix.dependencymanager", "3.1.0"),
+ junitBundles());
+ }
+
+ private String stateToString(int state) {
+ switch (state) {
+ case Bundle.ACTIVE:
+ return "ACTIVE";
+ case Bundle.INSTALLED:
+ return "INSTALLED";
+ case Bundle.RESOLVED:
+ return "RESOLVED";
+ case Bundle.UNINSTALLED:
+ return "UNINSTALLED";
+ default:
+ return "Not CONVERTED";
+ }
+ }
+
+ @Before
+ public void areWeReady() {
+ assertNotNull(bc);
+ boolean debugit = false;
+ Bundle b[] = bc.getBundles();
+ for (int i = 0; i < b.length; i++) {
+ int state = b[i].getState();
+ if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
+ log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
+ + stateToString(state));
+ debugit = true;
+ }
+ }
+ if (debugit) {
+ log.debug("Do some debugging because some bundle is "
+ + "unresolved");
+ }
+
+ // Assert if true, if false we are good to go!
+ assertFalse(debugit);
+
+ ServiceReference r = bc.getServiceReference(IStatisticsManager.class
+ .getName());
+ if (r != null) {
+ this.manager = (IStatisticsManager) bc.getService(r);
+ }
+ // If StatisticsManager is null, cannot run tests.
+ assertNotNull(this.manager);
+
+ }
+
+ @Test
+ public void testGetFlows() {
+ Node node = NodeCreator.createOFNode(1L);
+ List<FlowOnNode> flows = this.manager.getFlows(node);
+ FlowOnNode fn = flows.get(0);
+ Assert.assertTrue(fn.getByteCount() == 100);
+ Assert.assertTrue(fn.getDurationNanoseconds() == 400);
+ Assert.assertTrue(fn.getDurationSeconds() == 40);
+ Assert.assertTrue(fn.getTableId() == (byte) 0x1);
+ Assert.assertTrue(fn.getPacketCount() == 200);
+
+ Match match = new Match();
+ try {
+ match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
+ } catch (UnknownHostException e) {
+ fail("Couldn't create match");
+ }
+ Assert.assertTrue(match.equals(fn.getFlow().getMatch()));
+ Assert.assertTrue(fn.getFlow().getActions().get(0).equals(new Drop()));
+ }
+
+ @Test
+ public void testGetFlowStatistics() {
+ Flow flow = new Flow();
+
+ Match match = new Match();
+ try {
+ match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
+ } catch (UnknownHostException e) {
+ }
+ flow.setMatch(match);
+ Action action = new Drop();
+
+ List<Action> actions = new ArrayList<Action>();
+ actions.add(action);
+ flow.setActions(actions);
+
+ Node node = NodeCreator.createOFNode(1L);
+ FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
+ List<FlowEntry> list = new ArrayList<FlowEntry>();
+ list.add(fe);
+ FlowEntry fe2 = new FlowEntry("g1", "f2", flow, node);
+ list.add(fe2);
+
+ Map<Node, List<FlowOnNode>> result = this.manager
+ .getFlowStatisticsForFlowList(null);
+ Assert.assertTrue(result.isEmpty());
+ result = this.manager.getFlowStatisticsForFlowList(list);
+ List<FlowOnNode> results = result.get(node);
+ FlowOnNode fn = results.get(0);
+ Assert.assertTrue(fn.getByteCount() == 100);
+ Assert.assertTrue(fn.getDurationNanoseconds() == 400);
+ Assert.assertTrue(fn.getDurationSeconds() == 40);
+ Assert.assertTrue(fn.getTableId() == (byte) 0x1);
+ Assert.assertTrue(fn.getPacketCount() == 200);
+ Assert.assertTrue(fn.getFlow().equals(flow));
+
+ }
+
+ @Test
+ public void testGetFlowsNumber() {
+ Node node = NodeCreator.createOFNode(1L);
+ Assert.assertTrue(this.manager.getFlowsNumber(node) == 1);
+ }
+
+ @Test
+ public void testGetNodeDescription() {
+ Node node = NodeCreator.createOFNode(1L);
+ NodeDescription desc = this.manager.getNodeDescription(node);
+ Assert.assertTrue(desc.getDescription().equals(
+ "This is a sample node description"));
+ Assert.assertTrue(desc.getHardware().equals("stub hardware"));
+ Assert.assertTrue(desc.getSoftware().equals("stub software"));
+ Assert.assertTrue(desc.getSerialNumber().equals("123"));
+ Assert.assertTrue(desc.getManufacturer().equals("opendaylight"));
+
+ }
+
+ @Test
+ public void testGetNodeConnectorStatistics() {
+ Node node = NodeCreator.createOFNode(1L);
+ List<NodeConnectorStatistics> stats = this.manager
+ .getNodeConnectorStatistics(node);
+ NodeConnectorStatistics ns = stats.get(0);
+ Assert.assertTrue(ns.getCollisionCount() == 4);
+ Assert.assertTrue(ns.getReceiveByteCount() == 1000);
+ Assert.assertTrue(ns.getReceiveCRCErrorCount() == 1);
+ Assert.assertTrue(ns.getReceiveDropCount() == 2);
+ Assert.assertTrue(ns.getReceiveErrorCount() == 3);
+ Assert.assertTrue(ns.getReceiveFrameErrorCount() == 5);
+ Assert.assertTrue(ns.getReceiveOverRunErrorCount() == 6);
+ Assert.assertTrue(ns.getReceivePacketCount() == 250);
+ Assert.assertTrue(ns.getTransmitByteCount() == 5000);
+ Assert.assertTrue(ns.getTransmitDropCount() == 50);
+ Assert.assertTrue(ns.getTransmitErrorCount() == 10);
+ Assert.assertTrue(ns.getTransmitPacketCount() == 500);
+
+ NodeConnector nc = ns.getNodeConnector();
+ NodeConnectorStatistics ns2 = this.manager
+ .getNodeConnectorStatistics(nc);
+ Assert.assertTrue(ns2.getCollisionCount() == 4);
+ Assert.assertTrue(ns2.getReceiveByteCount() == 1000);
+ Assert.assertTrue(ns2.getReceiveCRCErrorCount() == 1);
+ Assert.assertTrue(ns2.getReceiveDropCount() == 2);
+ Assert.assertTrue(ns2.getReceiveErrorCount() == 3);
+ Assert.assertTrue(ns2.getReceiveFrameErrorCount() == 5);
+ Assert.assertTrue(ns2.getReceiveOverRunErrorCount() == 6);
+ Assert.assertTrue(ns2.getReceivePacketCount() == 250);
+ Assert.assertTrue(ns2.getTransmitByteCount() == 5000);
+ Assert.assertTrue(ns2.getTransmitDropCount() == 50);
+ Assert.assertTrue(ns2.getTransmitErrorCount() == 10);
+ Assert.assertTrue(ns2.getTransmitPacketCount() == 500);
+ }
+
+}
--- /dev/null
+<configuration scan="true">
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+ </pattern>
+ </encoder>
+ </appender>
+
+ <root level="error">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
import org.opendaylight.controller.sal.utils.GUIField;
import org.opendaylight.controller.switchmanager.SpanConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The class represents a Span Port configuration for a network node.
*/
public class SpanConfig implements Serializable {
+ protected static final Logger logger = LoggerFactory
+ .getLogger(SpanConfig.class);
private static final long serialVersionUID = 1L;
private static final String guiFields[] = { GUIField.NODE.toString(),
GUIField.SPANPORTS.toString() };
NodeConnectorIDType.OPENFLOW, Short.valueOf(j),
node));
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
} else {
NodeConnectorIDType.OPENFLOW, Short.valueOf(elem),
node));
} catch (NumberFormatException e) {
- e.printStackTrace();
+ logger.error("",e);
} catch (ConstructionException e) {
- e.printStackTrace();
+ logger.error("",e);
}
}
}
try {
nis = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e1) {
- e1.printStackTrace();
+ log.error("",e1);
return null;
}
byte[] MAC = null;
try {
MAC = ni.getHardwareAddress();
} catch (SocketException e) {
- e.printStackTrace();
+ log.error("",e);
}
if (MAC != null) {
return MAC;