\r
intentResolver.resolveIntent(userId);\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ log.error("Exception:",e);\r
}\r
}\r
}\r
import org.opendaylight.nemo.intent.IntentResolver;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.TimerTask;
* TimerTask for one condition.
*/
public class ConditionMonitor extends TimerTask {
+ private static Logger log = LoggerFactory.getLogger(ConditionMonitor.class);
private List<ConditionSegment> conditionSegments;
//Handle operation when condition state changed
private IntentResolver intentResolver;
try {
intentResolver.resolveIntent(userId);
} catch (Exception e) {
- e.printStackTrace();
+ //TODO Auto-generated catch block
+ log.error("Exception:",e);
}
preState = currentState;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.*;\r
import org.opendaylight.yangtools.yang.common.RpcResult;\r
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;\r
-\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
import java.util.concurrent.Future;\r
\r
import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.CommonRpcResult.ResultCode.Error;\r
* Created by z00293636 on 2015/9/7.\r
*/\r
public class UserManager implements NemoIntentService {\r
-\r
+ private static final Logger LOG = LoggerFactory.getLogger(UserManager.class);\r
private final DataBroker dataBroker;\r
\r
private RegisterUser registerUser;\r
outputBuilder.setResultCode(Ok).setMessage("The transaction ends.");\r
}\r
catch (IntentResolutionException e){\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
outputBuilder.setResultCode(Error).setMessage(e.getMessage());\r
}\r
catch (VNMappingException e){\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
outputBuilder.setResultCode(Error).setMessage(e.getMessage());\r
}\r
catch (Exception e){\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
else{\r
}\r
}\r
catch (ParseException e) {\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
outputBuilder.setResultCode(Error).setMessage(e.getMessage());\r
}\r
catch (NumberFormatException e) {\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
outputBuilder.setResultCode(Error).setMessage(e.getMessage());\r
}\r
return RpcResultBuilder.success(outputBuilder).buildFuture();\r
}\r
}\r
catch (NumberFormatException e){\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
outputBuilder.setResultCode(Error).setMessage(e.getMessage());\r
}\r
return RpcResultBuilder.success(outputBuilder).buildFuture();\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
f.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */\r
/* JavaCCOptions:KEEP_LINE_COL=null */\r
package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse;\r
+import java.util.Arrays;\r
\r
/**\r
* This exception is thrown when parse errors are encountered.\r
String[] tokenImageVal\r
)\r
{\r
- super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));\r
- currentToken = currentTokenVal;\r
- expectedTokenSequences = expectedTokenSequencesVal;\r
- tokenImage = tokenImageVal;\r
+\r
+ super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));\r
+ this.currentToken = currentTokenVal;\r
+ this.tokenImage = Arrays.copyOf(tokenImageVal,tokenImageVal.length);\r
+ this.expectedTokenSequences = Arrays.copyOf(expectedTokenSequencesVal,expectedTokenSequencesVal.length);\r
+// currentToken = currentTokenVal;\r
+// expectedTokenSequences = expectedTokenSequencesVal;\r
+// tokenImage = tokenImageVal;\r
}\r
\r
/**\r
maxNextCharInd = (bufpos -= tokenBegin);\r
}\r
}\r
- catch (Throwable t)\r
+ catch (Exception e)\r
{\r
- throw new Error(t.getMessage());\r
+ throw new Error(e.getMessage());\r
}\r
\r
\r
conditionparadefinitionFuture.get();\r
} catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
} catch (ExecutionException e){\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ LOG.error("Exception:",e);\r
}\r
return ;\r
}\r
try {\r
Thread.sleep(3000);\r
} catch (InterruptedException e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
}\r
}\r
try {\r
result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIid).get();\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()){\r
LOG.info("getUser OK");\r
result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, virtualNetworkIid).get();\r
\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()) {\r
LOG.info("getVirtualNetwork OK");\r
try {\r
result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get();\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()) {\r
LOG.info("getUserIntentVnMapping OK");\r
try {\r
result = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, physicalNetworkIid).get();\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()) {\r
LOG.info("getPhysicalNetwork OK");\r
\r
@Override\r
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {\r
- e.getCause().printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e.getCause());\r
+ // e.getCause().printStackTrace();\r
e.getChannel().close();\r
}\r
}\r
\r
@Override\r
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {\r
- e.getCause().printStackTrace();\r
+ // e.getCause().printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e.getCause());\r
e.getChannel().close();\r
}\r
}\r
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
return addResult[0];
}
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
return removeResult[0];
}
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
protected void removePhysicalLink(final PhysicalLinkKey physicalLinkKey){
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
-/*\r * Copyright (c) 2015 Huawei, 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\rpackage org.opendaylight.nemo.renderer.cli.physicalnetwork;\r\rimport com.fasterxml.jackson.databind.JsonNode;\rimport com.fasterxml.jackson.databind.ObjectMapper;\rimport com.google.common.collect.HashBasedTable;\rimport com.google.common.collect.Table;\rimport org.opendaylight.controller.md.sal.binding.api.DataBroker;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*;\rimport org.slf4j.Logger;\rimport org.slf4j.LoggerFactory;\r\rimport java.io.IOException;\rimport java.util.ArrayList;\rimport java.util.HashMap;\rimport java.util.List;\r\rpublic class PhysicalResourceLoader {\r\r private static final Logger log = LoggerFactory.getLogger(PhysicalResourceLoader.class);\r\r public final static String NODE_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-node-resource.json";\r public final static String LINK_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-link-resource.json";\r public final static String EXTERNAL_NETWORK_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-external-resource.json";\r public final static String HOST_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-host-resource.json";\r\r private final static String NODES = "node";\r private final static String NODE_ID = "node-id";\r private final static String NODE_TYPE = "node-type";\r\r private final static String PORTS = "port";\r private final static String PORT_ID = "port-id";\r private final static String PORT_TYPE = "port-type";\r private final static String PORT_IP = "port-ip-address";\r private final static String PORT_MAC = "port-mac-address";\r private final static String PORT_MASK = "mask";\r private final static String PORT_BANDWIDTH = "bandwidth";\r\r private final static String LINKS = "link";\r private final static String LINK_ID = "link-id";\r private final static String SRC_NODE_ID = "left-node-id";\r private final static String SRC_PORT_ID = "left-port-id";\r private final static String DST_NODE_ID = "right-node-id";\r private final static String DST_PORT_ID = "right-port-id";\r private final static String BANDWIDTH = "link-bandwidth";\r private final static String METRIC = "metric";\r private final static String DELAY = "delay";\r private final static String LOSS_RATE = "loss-rate";\r\r\r private final static String HOSTS = "host";\r private final static String HOST_NAME = "name";\r private final static String HOST_ID = "id";\r private final static String HOST_IPS = "ip-addresses";\r private final static String CONNECTOR_ID = "connector-id";\r\r private final static String IP_ADDRESS = "ip-address";\r private final static String MAC_ADDRESS = "mac-address";\r\r private final static String EXTERNAL_NETWORK = "external-network";\r\r private final static String ACCESS_NODE_ID = "access-node-id";\r private final static String ACCESS_PORT_ID = "access-port-id";\r private final static String LAYER = "layer";\r private final static String PROTOCOL = "protocol";\r\r\r private final static String ATTRIBUTES = "attribute";\r private final static String ATTRIBUTE_NAME = "name";\r private final static String ATTRIBUTE_VALUE = "value";\r\r protected final static long DEFAULT_PORT_BANDWIDTH = 10240;\r\r protected final static long DEFAULT_LINK_BANDWIDTH = 10240;\r protected final static long DEFAULT_LINK_DELAY = 1;\r protected final static short DEFAULT_LINK_LOSS_RATE = 1;\r private HashMap<PhysicalNodeId, PhysicalNode> physicalNodeHashMap;\r private HashMap<PhysicalPortId, PhysicalPort> physicalPortHashMap;\r private HashMap<PhysicalLinkId, PhysicalLink> physicalLinkHashMap;\r\r private ObjectMapper objectMapper = null;\r private DataBrokerAdapter dataBrokerAdapter = null;\r\r\r public PhysicalResourceLoader(DataBroker dataBroker) {\r physicalNodeHashMap = new HashMap<PhysicalNodeId, PhysicalNode>();\r physicalPortHashMap = new HashMap<PhysicalPortId, PhysicalPort>();\r physicalLinkHashMap = new HashMap<PhysicalLinkId, PhysicalLink>();\r\r this.objectMapper = new ObjectMapper();\r this.dataBrokerAdapter = new DataBrokerAdapter(dataBroker);\r\r loadNodesPorts();\r loadLinks();\r loadHosts();\r //loadExternals();\r }\r\r protected PhysicalNode getPhysicalNode(PhysicalNodeId physicalNodeId){\r return physicalNodeHashMap.get(physicalNodeId);\r }\r protected PhysicalPort getPhysicalPort(PhysicalPortId physicalPortId){\r return physicalPortHashMap.get(physicalPortId);\r }\r protected PhysicalLink getPhysicalLink(PhysicalLinkId physicalLinkId){\r return physicalLinkHashMap.get(physicalLinkId);\r }\r private void loadNodesPorts() {\r String nodesStr = Utils.readFile(NODE_PROPERTY);\r try {\r JsonNode nodeRoot = objectMapper.readTree(nodesStr);\r List<PhysicalNode> physicalNodes = buildNodes(nodeRoot);\r for (PhysicalNode physicalNode : physicalNodes) {\r physicalNodeHashMap.put(physicalNode.getNodeId(), physicalNode);\r for (PhysicalPort physicalPort : physicalNode.getPhysicalPort()) {\r physicalPortHashMap.put(physicalPort.getPortId(), physicalPort);\r }\r //lsx\r dataBrokerAdapter.addPhysicalNode(physicalNode);\r }\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r private void loadLinks() {\r String linkStr = Utils.readFile(LINK_PROPERTY);\r try {\r JsonNode linkRoot = objectMapper.readTree(linkStr);\r List<PhysicalLink> physicalLinks = buildLinks(linkRoot);\r for (PhysicalLink physicalLink : physicalLinks) {\r physicalLinkHashMap.put(physicalLink.getLinkId(), physicalLink);\r //lsx\r dataBrokerAdapter.addPhysicalLink(physicalLink);\r }\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r /*\r private void loadExternals() {\r String externalStr = Utils.readFile(EXTERNAL_NETWORK_MAC_PROPERTY);\r try {\r JsonNode externalRoot = objectMapper.readTree(externalStr);\r buildExternals(externalRoot);\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r */\r\r private void loadHosts() {\r String hostStr = Utils.readFile(HOST_PROPERTY);\r try {\r JsonNode hostRoot = objectMapper.readTree(hostStr);\r List<PhysicalHost> physicalHosts = buildHosts(hostRoot);\r for (PhysicalHost physicalHost : physicalHosts) {\r dataBrokerAdapter.addPhysicalHost(physicalHost);\r }\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r\r /*\r private void buildExternals(JsonNode externalRoot) {\r JsonNode exNetworkNodes = externalRoot.path(EXTERNAL_NETWORK_MAC);\r log.debug("Build external network mac : {} .", exNetworkNodes);\r for (int i = 0; i < exNetworkNodes.size(); i++) {\r log.debug("Build external network execution body");\r JsonNode exNetworkNode = exNetworkNodes.get(i);\r buildExNetwork(exNetworkNode);\r }\r }\r\r\r private void buildExNetwork(JsonNode exNetwork){\r String nodeId = exNetwork.get(NODE_ID).asText();\r String portId = exNetwork.get(PORT_ID).asText();\r String peerMac = exNetwork.get(MAC_ADDRESS).asText();\r PhysicalNodeId accessNodeId = new PhysicalNodeId(nodeId);\r PhysicalPortId accessPortId = new PhysicalPortId(portId);\r MacAddress macAddress = new MacAddress(peerMac);\r externalNetworkMac.put(accessNodeId,accessPortId,macAddress);\r }\r */\r\r private List<PhysicalNode> buildNodes(JsonNode nodesRoot) {\r List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>();\r JsonNode nodes = nodesRoot.path(NODES);\r log.debug("Build nodes: {} .", nodes);\r for (int i = 0; i < nodes.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode node = nodes.get(i);\r PhysicalNode phyNode = buildNode(node);\r if (phyNode != null) {\r physicalNodes.add(phyNode);\r }\r }\r return physicalNodes;\r }\r\r private PhysicalNode buildNode(JsonNode node) {\r PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder();\r\r String node_id = node.get(NODE_ID).asText();\r if (node_id.equals(""))\r return null;\r nodeBuilder.setNodeId(new PhysicalNodeId(node_id));\r PhysicalNodeKey key = new PhysicalNodeKey(nodeBuilder.getNodeId());\r nodeBuilder.setKey(key);\r\r String strType = node.get(NODE_TYPE).asText();\r PhysicalNodeInstance.NodeType nodeType = Utils.getNodeType(strType);\r nodeBuilder.setNodeType(nodeType);\r\r JsonNode ports = node.path(PORTS);\r List<PhysicalPort> phyPortList = buildPorts(ports);\r nodeBuilder.setPhysicalPort(phyPortList);\r\r JsonNode attributes = node.path(ATTRIBUTES);\r nodeBuilder.setAttribute(buildNodeAttributes(attributes));\r\r return nodeBuilder.build();\r }\r\r private List<PhysicalPort> buildPorts(JsonNode ports) {\r List<PhysicalPort> phyPortList = new ArrayList<PhysicalPort>();\r for (int j = 0; j < ports.size(); j++) {\r //JsonNode port = portIt.next();\r JsonNode port = ports.get(j);\r PhysicalPort physicalPort = buildPort(port);\r if (physicalPort != null) {\r phyPortList.add(physicalPort);\r }\r }\r return phyPortList;\r }\r\r private PhysicalPort buildPort(JsonNode port) {\r PhysicalPortBuilder physicalPortBuilder = new PhysicalPortBuilder();\r\r String strPortId = port.get(PORT_ID).asText();\r physicalPortBuilder.setPortId(new PhysicalPortId(strPortId));\r\r String strType = port.get(PORT_TYPE).asText();\r PhysicalPortInstance.PortType portType = Utils.getPortType(strType);\r physicalPortBuilder.setPortType(portType);\r\r //lsx port mac\r\r if(!(port.get("port-mac-address").asText().equals(""))){\r MacAddress mac = new MacAddress(port.get("port-mac-address").asText());\r physicalPortBuilder.setMacAddress(mac);\r }\r\r //lsx port bandwidth\r if(port.get("bandwidth").asText().equals("")) {\r physicalPortBuilder.setBandwidth(DEFAULT_PORT_BANDWIDTH);\r }\r else{\r physicalPortBuilder.setBandwidth((long) (port.get("bandwidth").asInt()));\r }\r\r JsonNode portAttributes = port.path(ATTRIBUTES);\r List<Attribute> attributes = buildPortAttributes(portAttributes);\r physicalPortBuilder.setAttribute(attributes);\r\r return physicalPortBuilder.build();\r }\r\r\r private List<Attribute> buildPortAttributes(JsonNode attributes) {\r List<Attribute> attributeList = new ArrayList<Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r Attribute attribute = buildPortAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private Attribute buildPortAttribute(JsonNode attribute) {\r AttributeBuilder attributeBuilder = new AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> buildNodeAttributes(JsonNode attributes) {\r List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> attributeList =\r new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute attribute = buildNodeAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute buildNodeAttribute(JsonNode attribute) {\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder attributeBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r\r private List<PhysicalLink> buildLinks(JsonNode linksRoot) {\r List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>();\r JsonNode links = linksRoot.path(LINKS);\r log.debug("Build links: {} .", links);\r for (int i = 0; i < links.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode link = links.get(i);\r PhysicalLink phyLink = buildLink(link);\r if (phyLink != null) {\r physicalLinks.add(phyLink);\r }\r }\r return physicalLinks;\r }\r\r private PhysicalLink buildLink(JsonNode linkNode) {\r PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder();\r\r String strLinkId = linkNode.get(LINK_ID).asText();\r linkBuilder.setLinkId(new PhysicalLinkId(strLinkId));\r\r //lsx\r linkBuilder.setSrcNodeId(new PhysicalNodeId(linkNode.get(SRC_NODE_ID).asText()));\r linkBuilder.setSrcPortId(new PhysicalPortId(linkNode.get(SRC_PORT_ID).asText()));\r linkBuilder.setDestNodeId(new PhysicalNodeId(linkNode.get(DST_NODE_ID).asText()));\r linkBuilder.setDestPortId(new PhysicalPortId(linkNode.get(DST_PORT_ID).asText()));\r\r //lsx\r if(linkNode.get("link-bandwidth").asText().equals("")) {\r\r linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH);\r }else{\r linkBuilder.setBandwidth((long) (linkNode.get("link-bandwidth").asLong()));\r }\r\r long metric = linkNode.get(METRIC).asLong();\r linkBuilder.setMetric(metric);\r\r linkBuilder.setDelay(DEFAULT_LINK_DELAY);\r linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE);\r\r return linkBuilder.build();\r }\r\r private List<PhysicalHost> buildHosts(JsonNode hostsNode) {\r List<PhysicalHost> physicalHosts = new ArrayList<PhysicalHost>();\r JsonNode hosts = hostsNode.path(HOSTS);\r log.debug("Build hosts: {} .", hosts);\r for (int i = 0; i < hosts.size(); i++) {\r JsonNode host = hosts.get(i);\r PhysicalHost physicalHost = buildHost(host);\r if (physicalHost != null) {\r physicalHosts.add(physicalHost);\r }\r }\r return physicalHosts;\r }\r\r private PhysicalHost buildHost(JsonNode hostNode) {\r PhysicalHostBuilder hostBuilder = new PhysicalHostBuilder();\r hostBuilder.setHostId(new PhysicalHostId(hostNode.get(HOST_ID).asText()));\r hostBuilder.setKey(new PhysicalHostKey(hostBuilder.getHostId()));\r hostBuilder.setHostName(new PhysicalHostName(hostNode.get(HOST_NAME).asText()));\r\r IpAddressesBuilder IpAddrBuilder = new IpAddressesBuilder();\r List<IpAddress> ipList = new ArrayList<IpAddress>();\r\r JsonNode ipaddrs = hostNode.path(HOST_IPS);\r for (int p = 0; p < ipaddrs.size(); p++) {\r JsonNode ipaddr = ipaddrs.get(p);\r IpAddress ip = new IpAddress(new Ipv4Address(ipaddr.get(IP_ADDRESS).asText()));\r ipList.add(ip);\r }\r\r IpAddrBuilder.setIpAddress(ipList);\r hostBuilder.setIpAddresses(IpAddrBuilder.build());\r MacAddress mac = new MacAddress(hostNode.get(MAC_ADDRESS).asText());\r hostBuilder.setMacAddress(mac);\r hostBuilder.setNodeId(new PhysicalNodeId(hostNode.get(NODE_ID).asText()));\r hostBuilder.setPortId(new PhysicalPortId(hostNode.get(CONNECTOR_ID).asText()));\r\r return hostBuilder.build();\r }\r\r\r public void close() {\r physicalLinkHashMap.clear();\r physicalPortHashMap.clear();\r physicalNodeHashMap.clear();\r //externalNetworkMac.clear();\r }\r}\r
\ No newline at end of file
+/*\r * Copyright (c) 2015 Huawei, 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\rpackage org.opendaylight.nemo.renderer.cli.physicalnetwork;\r\rimport com.fasterxml.jackson.databind.JsonNode;\rimport com.fasterxml.jackson.databind.ObjectMapper;\rimport com.google.common.collect.HashBasedTable;\rimport com.google.common.collect.Table;\rimport org.opendaylight.controller.md.sal.binding.api.DataBroker;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*;\rimport org.slf4j.Logger;\rimport org.slf4j.LoggerFactory;\r\rimport java.io.IOException;\rimport java.util.ArrayList;\rimport java.util.HashMap;\rimport java.util.List;\r\rpublic class PhysicalResourceLoader {\r\r private static final Logger log = LoggerFactory.getLogger(PhysicalResourceLoader.class);\r\r public final static String NODE_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-node-resource.json";\r public final static String LINK_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-link-resource.json";\r public final static String EXTERNAL_NETWORK_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-external-resource.json";\r public final static String HOST_PROPERTY = "etc/opendaylight/karaf/nemo-cli-renderer-host-resource.json";\r\r private final static String NODES = "node";\r private final static String NODE_ID = "node-id";\r private final static String NODE_TYPE = "node-type";\r\r private final static String PORTS = "port";\r private final static String PORT_ID = "port-id";\r private final static String PORT_TYPE = "port-type";\r private final static String PORT_IP = "port-ip-address";\r private final static String PORT_MAC = "port-mac-address";\r private final static String PORT_MASK = "mask";\r private final static String PORT_BANDWIDTH = "bandwidth";\r\r private final static String LINKS = "link";\r private final static String LINK_ID = "link-id";\r private final static String SRC_NODE_ID = "left-node-id";\r private final static String SRC_PORT_ID = "left-port-id";\r private final static String DST_NODE_ID = "right-node-id";\r private final static String DST_PORT_ID = "right-port-id";\r private final static String BANDWIDTH = "link-bandwidth";\r private final static String METRIC = "metric";\r private final static String DELAY = "delay";\r private final static String LOSS_RATE = "loss-rate";\r\r\r private final static String HOSTS = "host";\r private final static String HOST_NAME = "name";\r private final static String HOST_ID = "id";\r private final static String HOST_IPS = "ip-addresses";\r private final static String CONNECTOR_ID = "connector-id";\r\r private final static String IP_ADDRESS = "ip-address";\r private final static String MAC_ADDRESS = "mac-address";\r\r private final static String EXTERNAL_NETWORK = "external-network";\r\r private final static String ACCESS_NODE_ID = "access-node-id";\r private final static String ACCESS_PORT_ID = "access-port-id";\r private final static String LAYER = "layer";\r private final static String PROTOCOL = "protocol";\r\r\r private final static String ATTRIBUTES = "attribute";\r private final static String ATTRIBUTE_NAME = "name";\r private final static String ATTRIBUTE_VALUE = "value";\r\r protected final static long DEFAULT_PORT_BANDWIDTH = 10240;\r\r protected final static long DEFAULT_LINK_BANDWIDTH = 10240;\r protected final static long DEFAULT_LINK_DELAY = 1;\r protected final static short DEFAULT_LINK_LOSS_RATE = 1;\r private HashMap<PhysicalNodeId, PhysicalNode> physicalNodeHashMap;\r private HashMap<PhysicalPortId, PhysicalPort> physicalPortHashMap;\r private HashMap<PhysicalLinkId, PhysicalLink> physicalLinkHashMap;\r\r private ObjectMapper objectMapper = null;\r private DataBrokerAdapter dataBrokerAdapter = null;\r\r\r public PhysicalResourceLoader(DataBroker dataBroker) {\r physicalNodeHashMap = new HashMap<PhysicalNodeId, PhysicalNode>();\r physicalPortHashMap = new HashMap<PhysicalPortId, PhysicalPort>();\r physicalLinkHashMap = new HashMap<PhysicalLinkId, PhysicalLink>();\r\r this.objectMapper = new ObjectMapper();\r this.dataBrokerAdapter = new DataBrokerAdapter(dataBroker);\r\r loadNodesPorts();\r loadLinks();\r loadHosts();\r //loadExternals();\r }\r\r protected PhysicalNode getPhysicalNode(PhysicalNodeId physicalNodeId){\r return physicalNodeHashMap.get(physicalNodeId);\r }\r protected PhysicalPort getPhysicalPort(PhysicalPortId physicalPortId){\r return physicalPortHashMap.get(physicalPortId);\r }\r protected PhysicalLink getPhysicalLink(PhysicalLinkId physicalLinkId){\r return physicalLinkHashMap.get(physicalLinkId);\r }\r private void loadNodesPorts() {\r String nodesStr = Utils.readFile(NODE_PROPERTY);\r try {\r JsonNode nodeRoot = objectMapper.readTree(nodesStr);\r List<PhysicalNode> physicalNodes = buildNodes(nodeRoot);\r for (PhysicalNode physicalNode : physicalNodes) {\r physicalNodeHashMap.put(physicalNode.getNodeId(), physicalNode);\r for (PhysicalPort physicalPort : physicalNode.getPhysicalPort()) {\r physicalPortHashMap.put(physicalPort.getPortId(), physicalPort);\r }\r //lsx\r dataBrokerAdapter.addPhysicalNode(physicalNode);\r }\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception:",e);\r }\r }\r\r private void loadLinks() {\r String linkStr = Utils.readFile(LINK_PROPERTY);\r try {\r JsonNode linkRoot = objectMapper.readTree(linkStr);\r List<PhysicalLink> physicalLinks = buildLinks(linkRoot);\r for (PhysicalLink physicalLink : physicalLinks) {\r physicalLinkHashMap.put(physicalLink.getLinkId(), physicalLink);\r //lsx\r dataBrokerAdapter.addPhysicalLink(physicalLink);\r }\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception:",e);\r }\r }\r\r /*\r private void loadExternals() {\r String externalStr = Utils.readFile(EXTERNAL_NETWORK_MAC_PROPERTY);\r try {\r JsonNode externalRoot = objectMapper.readTree(externalStr);\r buildExternals(externalRoot);\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r */\r\r private void loadHosts() {\r String hostStr = Utils.readFile(HOST_PROPERTY);\r try {\r JsonNode hostRoot = objectMapper.readTree(hostStr);\r List<PhysicalHost> physicalHosts = buildHosts(hostRoot);\r for (PhysicalHost physicalHost : physicalHosts) {\r dataBrokerAdapter.addPhysicalHost(physicalHost);\r }\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception:",e);\r }\r }\r\r\r /*\r private void buildExternals(JsonNode externalRoot) {\r JsonNode exNetworkNodes = externalRoot.path(EXTERNAL_NETWORK_MAC);\r log.debug("Build external network mac : {} .", exNetworkNodes);\r for (int i = 0; i < exNetworkNodes.size(); i++) {\r log.debug("Build external network execution body");\r JsonNode exNetworkNode = exNetworkNodes.get(i);\r buildExNetwork(exNetworkNode);\r }\r }\r\r\r private void buildExNetwork(JsonNode exNetwork){\r String nodeId = exNetwork.get(NODE_ID).asText();\r String portId = exNetwork.get(PORT_ID).asText();\r String peerMac = exNetwork.get(MAC_ADDRESS).asText();\r PhysicalNodeId accessNodeId = new PhysicalNodeId(nodeId);\r PhysicalPortId accessPortId = new PhysicalPortId(portId);\r MacAddress macAddress = new MacAddress(peerMac);\r externalNetworkMac.put(accessNodeId,accessPortId,macAddress);\r }\r */\r\r private List<PhysicalNode> buildNodes(JsonNode nodesRoot) {\r List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>();\r JsonNode nodes = nodesRoot.path(NODES);\r log.debug("Build nodes: {} .", nodes);\r for (int i = 0; i < nodes.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode node = nodes.get(i);\r PhysicalNode phyNode = buildNode(node);\r if (phyNode != null) {\r physicalNodes.add(phyNode);\r }\r }\r return physicalNodes;\r }\r\r private PhysicalNode buildNode(JsonNode node) {\r PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder();\r\r String node_id = node.get(NODE_ID).asText();\r if (node_id.equals(""))\r return null;\r nodeBuilder.setNodeId(new PhysicalNodeId(node_id));\r PhysicalNodeKey key = new PhysicalNodeKey(nodeBuilder.getNodeId());\r nodeBuilder.setKey(key);\r\r String strType = node.get(NODE_TYPE).asText();\r PhysicalNodeInstance.NodeType nodeType = Utils.getNodeType(strType);\r nodeBuilder.setNodeType(nodeType);\r\r JsonNode ports = node.path(PORTS);\r List<PhysicalPort> phyPortList = buildPorts(ports);\r nodeBuilder.setPhysicalPort(phyPortList);\r\r JsonNode attributes = node.path(ATTRIBUTES);\r nodeBuilder.setAttribute(buildNodeAttributes(attributes));\r\r return nodeBuilder.build();\r }\r\r private List<PhysicalPort> buildPorts(JsonNode ports) {\r List<PhysicalPort> phyPortList = new ArrayList<PhysicalPort>();\r for (int j = 0; j < ports.size(); j++) {\r //JsonNode port = portIt.next();\r JsonNode port = ports.get(j);\r PhysicalPort physicalPort = buildPort(port);\r if (physicalPort != null) {\r phyPortList.add(physicalPort);\r }\r }\r return phyPortList;\r }\r\r private PhysicalPort buildPort(JsonNode port) {\r PhysicalPortBuilder physicalPortBuilder = new PhysicalPortBuilder();\r\r String strPortId = port.get(PORT_ID).asText();\r physicalPortBuilder.setPortId(new PhysicalPortId(strPortId));\r\r String strType = port.get(PORT_TYPE).asText();\r PhysicalPortInstance.PortType portType = Utils.getPortType(strType);\r physicalPortBuilder.setPortType(portType);\r\r //lsx port mac\r\r if(!(port.get("port-mac-address").asText().equals(""))){\r MacAddress mac = new MacAddress(port.get("port-mac-address").asText());\r physicalPortBuilder.setMacAddress(mac);\r }\r\r //lsx port bandwidth\r if(port.get("bandwidth").asText().equals("")) {\r physicalPortBuilder.setBandwidth(DEFAULT_PORT_BANDWIDTH);\r }\r else{\r physicalPortBuilder.setBandwidth((long) (port.get("bandwidth").asInt()));\r }\r\r JsonNode portAttributes = port.path(ATTRIBUTES);\r List<Attribute> attributes = buildPortAttributes(portAttributes);\r physicalPortBuilder.setAttribute(attributes);\r\r return physicalPortBuilder.build();\r }\r\r\r private List<Attribute> buildPortAttributes(JsonNode attributes) {\r List<Attribute> attributeList = new ArrayList<Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r Attribute attribute = buildPortAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private Attribute buildPortAttribute(JsonNode attribute) {\r AttributeBuilder attributeBuilder = new AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> buildNodeAttributes(JsonNode attributes) {\r List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> attributeList =\r new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute attribute = buildNodeAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute buildNodeAttribute(JsonNode attribute) {\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder attributeBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r\r private List<PhysicalLink> buildLinks(JsonNode linksRoot) {\r List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>();\r JsonNode links = linksRoot.path(LINKS);\r log.debug("Build links: {} .", links);\r for (int i = 0; i < links.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode link = links.get(i);\r PhysicalLink phyLink = buildLink(link);\r if (phyLink != null) {\r physicalLinks.add(phyLink);\r }\r }\r return physicalLinks;\r }\r\r private PhysicalLink buildLink(JsonNode linkNode) {\r PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder();\r\r String strLinkId = linkNode.get(LINK_ID).asText();\r linkBuilder.setLinkId(new PhysicalLinkId(strLinkId));\r\r //lsx\r linkBuilder.setSrcNodeId(new PhysicalNodeId(linkNode.get(SRC_NODE_ID).asText()));\r linkBuilder.setSrcPortId(new PhysicalPortId(linkNode.get(SRC_PORT_ID).asText()));\r linkBuilder.setDestNodeId(new PhysicalNodeId(linkNode.get(DST_NODE_ID).asText()));\r linkBuilder.setDestPortId(new PhysicalPortId(linkNode.get(DST_PORT_ID).asText()));\r\r //lsx\r if(linkNode.get("link-bandwidth").asText().equals("")) {\r\r linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH);\r }else{\r linkBuilder.setBandwidth((long) (linkNode.get("link-bandwidth").asLong()));\r }\r\r long metric = linkNode.get(METRIC).asLong();\r linkBuilder.setMetric(metric);\r\r linkBuilder.setDelay(DEFAULT_LINK_DELAY);\r linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE);\r\r return linkBuilder.build();\r }\r\r private List<PhysicalHost> buildHosts(JsonNode hostsNode) {\r List<PhysicalHost> physicalHosts = new ArrayList<PhysicalHost>();\r JsonNode hosts = hostsNode.path(HOSTS);\r log.debug("Build hosts: {} .", hosts);\r for (int i = 0; i < hosts.size(); i++) {\r JsonNode host = hosts.get(i);\r PhysicalHost physicalHost = buildHost(host);\r if (physicalHost != null) {\r physicalHosts.add(physicalHost);\r }\r }\r return physicalHosts;\r }\r\r private PhysicalHost buildHost(JsonNode hostNode) {\r PhysicalHostBuilder hostBuilder = new PhysicalHostBuilder();\r hostBuilder.setHostId(new PhysicalHostId(hostNode.get(HOST_ID).asText()));\r hostBuilder.setKey(new PhysicalHostKey(hostBuilder.getHostId()));\r hostBuilder.setHostName(new PhysicalHostName(hostNode.get(HOST_NAME).asText()));\r\r IpAddressesBuilder IpAddrBuilder = new IpAddressesBuilder();\r List<IpAddress> ipList = new ArrayList<IpAddress>();\r\r JsonNode ipaddrs = hostNode.path(HOST_IPS);\r for (int p = 0; p < ipaddrs.size(); p++) {\r JsonNode ipaddr = ipaddrs.get(p);\r IpAddress ip = new IpAddress(new Ipv4Address(ipaddr.get(IP_ADDRESS).asText()));\r ipList.add(ip);\r }\r\r IpAddrBuilder.setIpAddress(ipList);\r hostBuilder.setIpAddresses(IpAddrBuilder.build());\r MacAddress mac = new MacAddress(hostNode.get(MAC_ADDRESS).asText());\r hostBuilder.setMacAddress(mac);\r hostBuilder.setNodeId(new PhysicalNodeId(hostNode.get(NODE_ID).asText()));\r hostBuilder.setPortId(new PhysicalPortId(hostNode.get(CONNECTOR_ID).asText()));\r\r return hostBuilder.build();\r }\r\r\r public void close() {\r physicalLinkHashMap.clear();\r physicalPortHashMap.clear();\r physicalNodeHashMap.clear();\r //externalNetworkMac.clear();\r }\r}\r
\ No newline at end of file
}
reader.close();
}catch(IOException e){
- e.printStackTrace();
+ // TODO Auto-generated catch block
}finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
}
}
}
try {\r
result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIid).get();\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()){\r
LOG.debug("getUser OK");\r
result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, virtualNetworkIid).get();\r
\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()) {\r
LOG.debug("getVirtualNetwork OK");\r
try {\r
result = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, userIntentVnMappingIid).get();\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()) {\r
LOG.debug("getUserIntentVnMapping OK");\r
try {\r
result = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, physicalNetworkIid).get();\r
} catch (Exception e) {\r
- e.printStackTrace();\r
+ // TODO Auto-generated catch block\r
+ LOG.error("Exception:",e);\r
}\r
if (result.isPresent()) {\r
LOG.debug("getPhysicalNetwork OK");\r
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
return addResult[0];
}
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
return removeResult[0];
}
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
protected void removePhysicalLink(final PhysicalLinkKey physicalLinkKey){
});
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
-/*\r * Copyright (c) 2015 Huawei, 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\rpackage org.opendaylight.nemo.renderer.openflow.physicalnetwork;\r\rimport com.fasterxml.jackson.databind.JsonNode;\rimport com.fasterxml.jackson.databind.ObjectMapper;\rimport com.google.common.collect.HashBasedTable;\rimport com.google.common.collect.Table;\rimport org.opendaylight.controller.md.sal.binding.api.DataBroker;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*;\rimport org.slf4j.Logger;\rimport org.slf4j.LoggerFactory;\r\rimport java.io.IOException;\rimport java.util.ArrayList;\rimport java.util.HashMap;\rimport java.util.List;\r\rpublic class PhyConfigLoader {\r\r private static final Logger log = LoggerFactory.getLogger(PhyConfigLoader.class);\r\r public final static String NODE_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-node-resource.json";\r public final static String LINK_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-link-resource.json";\r public final static String EXTERNAL_NETWORK_MAC_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-external-resource.json";\r public final static String HOST_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-host-resource.json";\r\r private final static String NODES = "node";\r private final static String NODE_ID = "node-id";\r private final static String NODE_TYPE = "node-type";\r\r private final static String PORTS = "port";\r private final static String PORT_ID = "port-id";\r private final static String PORT_TYPE = "port-type";\r private final static String PORT_IP = "port-ip-address";\r private final static String PORT_MAC = "port-mac-address";\r\r private final static String LINKS = "link";\r private final static String LINK_ID = "link-id";\r private final static String SRC_NODE_ID = "left-node-id";\r private final static String SRC_PORT_ID = "left-port-id";\r private final static String DST_NODE_ID = "right-node-id";\r private final static String DST_PORT_ID = "right-port-id";\r private final static String BANDWIDTH = "link-bandwidth";\r private final static String METRIC = "metric";\r\r\r private final static String HOSTS = "host";\r private final static String HOST_NAME = "name";\r private final static String HOST_ID = "id";\r private final static String HOST_IPS = "ip-addresses";\r private final static String CONNECTOR_ID = "connector-id";\r\r private final static String EXTERNAL_NETWORK_MAC = "external-network-mac";\r\r private final static String IP_ADDRESS = "ip-address";\r private final static String MAC_ADDRESS = "mac-address";\r\r private final static String ATTRIBUTES = "attribute";\r private final static String ATTRIBUTE_NAME = "name";\r private final static String ATTRIBUTE_VALUE = "value";\r\r protected final static long DEFAULT_LINK_BANDWIDTH = 10240;\r protected final static long DEFAULT_LINK_DELAY = 1;\r protected final static short DEFAULT_LINK_LOSS_RATE = 1;\r private HashMap<PhysicalNodeId, PhysicalNode> physicalNodeHashMap;\r private HashMap<PhysicalPortId, PhysicalPort> physicalPortHashMap;\r private HashMap<PhysicalLinkId, PhysicalLink> physicalLinkHashMap;\r private Table<PhysicalNodeId, PhysicalPortId, MacAddress> externalNetworkMac;\r// final private DataBroker dataProvider;\r\r private ObjectMapper objectMapper = null;\r private DataBrokerAdapter dataBrokerAdapter = null;\r\r\r\r public PhyConfigLoader(DataBroker dataBroker) {\r physicalNodeHashMap = new HashMap<PhysicalNodeId, PhysicalNode>();\r physicalPortHashMap = new HashMap<PhysicalPortId, PhysicalPort>();\r physicalLinkHashMap = new HashMap<PhysicalLinkId, PhysicalLink>();\r externalNetworkMac = HashBasedTable.create();\r\r this.objectMapper = new ObjectMapper();\r this.dataBrokerAdapter = new DataBrokerAdapter(dataBroker);\r\r loadNodesPorts();\r loadLinks();\r loadHosts();\r loadExternals();\r }\r\r public Table<PhysicalNodeId, PhysicalPortId, MacAddress> getExternalNetworkMac() {\r return externalNetworkMac;\r }\r protected PhysicalNode getPhysicalNode(PhysicalNodeId physicalNodeId){\r return physicalNodeHashMap.get(physicalNodeId);\r }\r protected PhysicalPort getPhysicalPort(PhysicalPortId physicalPortId){\r return physicalPortHashMap.get(physicalPortId);\r }\r protected PhysicalLink getPhysicalLink(PhysicalLinkId physicalLinkId){\r return physicalLinkHashMap.get(physicalLinkId);\r }\r private void loadNodesPorts() {\r String nodesStr = Utils.readFile(NODE_PROPERTY);\r try {\r JsonNode nodeRoot = objectMapper.readTree(nodesStr);\r List<PhysicalNode> physicalNodes = buildNodes(nodeRoot);\r for (PhysicalNode physicalNode : physicalNodes) {\r physicalNodeHashMap.put(physicalNode.getNodeId(), physicalNode);\r for (PhysicalPort physicalPort : physicalNode.getPhysicalPort()) {\r physicalPortHashMap.put(physicalPort.getPortId(), physicalPort);\r }\r }\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r private void loadLinks() {\r String linkStr = Utils.readFile(LINK_PROPERTY);\r try {\r JsonNode linkRoot = objectMapper.readTree(linkStr);\r List<PhysicalLink> physicalLinks = buildLinks(linkRoot);\r for (PhysicalLink physicalLink : physicalLinks) {\r physicalLinkHashMap.put(physicalLink.getLinkId(), physicalLink);\r }\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r private void loadExternals() {\r String externalStr = Utils.readFile(EXTERNAL_NETWORK_MAC_PROPERTY);\r try {\r JsonNode externalRoot = objectMapper.readTree(externalStr);\r buildExternals(externalRoot);\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r private void loadHosts() {\r String hostStr = Utils.readFile(HOST_PROPERTY);\r try {\r JsonNode hostRoot = objectMapper.readTree(hostStr);\r List<PhysicalHost> physicalHosts = buildHosts(hostRoot);\r for (PhysicalHost physicalHost : physicalHosts) {\r dataBrokerAdapter.addPhysicalHost(physicalHost);\r }\r } catch (IOException e) {\r e.printStackTrace();\r }\r }\r\r private void buildExternals(JsonNode externalRoot) {\r JsonNode exNetworkNodes = externalRoot.path(EXTERNAL_NETWORK_MAC);\r log.debug("Build external network mac : {} .", exNetworkNodes);\r for (int i = 0; i < exNetworkNodes.size(); i++) {\r log.debug("Build external network execution body");\r JsonNode exNetworkNode = exNetworkNodes.get(i);\r buildExNetwork(exNetworkNode);\r }\r }\r private void buildExNetwork(JsonNode exNetwork){\r String nodeId = exNetwork.get(NODE_ID).asText();\r String portId = exNetwork.get(PORT_ID).asText();\r String peerMac = exNetwork.get(MAC_ADDRESS).asText();\r PhysicalNodeId accessNodeId = new PhysicalNodeId(nodeId);\r PhysicalPortId accessPortId = new PhysicalPortId(portId);\r MacAddress macAddress = new MacAddress(peerMac);\r externalNetworkMac.put(accessNodeId,accessPortId,macAddress);\r }\r\r private List<PhysicalNode> buildNodes(JsonNode nodesRoot) {\r List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>();\r JsonNode nodes = nodesRoot.path(NODES);\r log.debug("Build nodes: {} .", nodes);\r for (int i = 0; i < nodes.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode node = nodes.get(i);\r PhysicalNode phyNode = buildNode(node);\r if (phyNode != null) {\r physicalNodes.add(phyNode);\r }\r }\r return physicalNodes;\r }\r\r private PhysicalNode buildNode(JsonNode node) {\r PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder();\r\r String node_id = node.get(NODE_ID).asText();\r if (node_id.equals(""))\r return null;\r nodeBuilder.setNodeId(new PhysicalNodeId(node_id));\r PhysicalNodeKey key = new PhysicalNodeKey(nodeBuilder.getNodeId());\r nodeBuilder.setKey(key);\r\r String strType = node.get(NODE_TYPE).asText();\r PhysicalNodeInstance.NodeType nodeType = Utils.getNodeType(strType);\r nodeBuilder.setNodeType(nodeType);\r\r JsonNode ports = node.path(PORTS);\r List<PhysicalPort> phyPortList = buildPorts(ports);\r nodeBuilder.setPhysicalPort(phyPortList);\r\r JsonNode attributes = node.path(ATTRIBUTES);\r nodeBuilder.setAttribute(buildNodeAttributes(attributes));\r\r return nodeBuilder.build();\r }\r\r private List<PhysicalPort> buildPorts(JsonNode ports) {\r List<PhysicalPort> phyPortList = new ArrayList<PhysicalPort>();\r for (int j = 0; j < ports.size(); j++) {\r //JsonNode port = portIt.next();\r JsonNode port = ports.get(j);\r PhysicalPort physicalPort = buildPort(port);\r if (physicalPort != null) {\r phyPortList.add(physicalPort);\r }\r }\r return phyPortList;\r }\r\r private PhysicalPort buildPort(JsonNode port) {\r PhysicalPortBuilder physicalPortBuilder = new PhysicalPortBuilder();\r\r String strPortId = port.get(PORT_ID).asText();\r physicalPortBuilder.setPortId(new PhysicalPortId(strPortId));\r\r String strType = port.get(PORT_TYPE).asText();\r PhysicalPortInstance.PortType portType = Utils.getPortType(strType);\r physicalPortBuilder.setPortType(portType);\r\r// String strMac = port.get(PORT_MAC).asText();\r// MacAddress macAddress = new MacAddress(strMac);\r// physicalPortBuilder.setMacAddress(macAddress);\r//\r// long bandWidth = port.get(BANDWIDTH).asLong();\r// physicalPortBuilder.setBandwidth(bandWidth);\r\r JsonNode portAttributes = port.path(ATTRIBUTES);\r List<Attribute> attributes = buildPortAttributes(portAttributes);\r physicalPortBuilder.setAttribute(attributes);\r\r return physicalPortBuilder.build();\r }\r\r private List<Attribute> buildPortAttributes(JsonNode attributes) {\r List<Attribute> attributeList = new ArrayList<Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r Attribute attribute = buildPortAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private Attribute buildPortAttribute(JsonNode attribute) {\r AttributeBuilder attributeBuilder = new AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> buildNodeAttributes(JsonNode attributes) {\r List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> attributeList =\r new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute attribute = buildNodeAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute buildNodeAttribute(JsonNode attribute) {\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder attributeBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r\r private List<PhysicalLink> buildLinks(JsonNode linksRoot) {\r List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>();\r JsonNode links = linksRoot.path(LINKS);\r log.debug("Build links: {} .", links);\r for (int i = 0; i < links.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode link = links.get(i);\r PhysicalLink phyLink = buildLink(link);\r if (phyLink != null) {\r physicalLinks.add(phyLink);\r }\r }\r return physicalLinks;\r }\r\r private PhysicalLink buildLink(JsonNode linkNode) {\r PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder();\r\r String strLinkId = linkNode.get(LINK_ID).asText();\r long metric = linkNode.get(METRIC).asLong();\r\r linkBuilder.setLinkId(new PhysicalLinkId(strLinkId));\r linkBuilder.setMetric(metric);\r\r linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH);\r linkBuilder.setDelay(DEFAULT_LINK_DELAY);\r linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE);\r\r return linkBuilder.build();\r }\r\r private List<PhysicalHost> buildHosts(JsonNode hostsNode) {\r List<PhysicalHost> physicalHosts = new ArrayList<PhysicalHost>();\r JsonNode hosts = hostsNode.path(HOSTS);\r log.debug("Build hosts: {} .", hosts);\r for (int i = 0; i < hosts.size(); i++) {\r JsonNode host = hosts.get(i);\r PhysicalHost physicalHost = buildHost(host);\r if (physicalHost != null) {\r physicalHosts.add(physicalHost);\r }\r }\r return physicalHosts;\r }\r\r private PhysicalHost buildHost(JsonNode hostNode) {\r PhysicalHostBuilder hostBuilder = new PhysicalHostBuilder();\r hostBuilder.setHostId(new PhysicalHostId(hostNode.get(HOST_ID).asText()));\r hostBuilder.setKey(new PhysicalHostKey(hostBuilder.getHostId()));\r hostBuilder.setHostName(new PhysicalHostName(hostNode.get(HOST_NAME).asText()));\r\r IpAddressesBuilder IpAddrBuilder = new IpAddressesBuilder();\r List<IpAddress> ipList = new ArrayList<IpAddress>();\r\r JsonNode ipaddrs = hostNode.path(HOST_IPS);\r for (int p = 0; p < ipaddrs.size(); p++) {\r JsonNode ipaddr = ipaddrs.get(p);\r IpAddress ip = new IpAddress(new Ipv4Address(ipaddr.get(IP_ADDRESS).asText()));\r ipList.add(ip);\r }\r\r IpAddrBuilder.setIpAddress(ipList);\r hostBuilder.setIpAddresses(IpAddrBuilder.build());\r MacAddress mac = new MacAddress(hostNode.get(MAC_ADDRESS).asText());\r hostBuilder.setMacAddress(mac);\r hostBuilder.setNodeId(new PhysicalNodeId(hostNode.get(NODE_ID).asText()));\r hostBuilder.setPortId(new PhysicalPortId(hostNode.get(CONNECTOR_ID).asText()));\r\r return hostBuilder.build();\r }\r\r\r public void close() {\r physicalLinkHashMap.clear();\r physicalPortHashMap.clear();\r physicalNodeHashMap.clear();\r externalNetworkMac.clear();\r }\r\r\r}\r
\ No newline at end of file
+/*\r * Copyright (c) 2015 Huawei, 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\rpackage org.opendaylight.nemo.renderer.openflow.physicalnetwork;\r\rimport com.fasterxml.jackson.databind.JsonNode;\rimport com.fasterxml.jackson.databind.ObjectMapper;\rimport com.google.common.collect.HashBasedTable;\rimport com.google.common.collect.Table;\rimport org.opendaylight.controller.md.sal.binding.api.DataBroker;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;\rimport org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.attribute.instance.AttributeValueBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.host.instance.IpAddressesBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPort;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.PhysicalPortBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.Attribute;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeBuilder;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.port.instance.AttributeKey;\rimport org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.*;\rimport org.slf4j.Logger;\rimport org.slf4j.LoggerFactory;\r\rimport java.io.IOException;\rimport java.util.ArrayList;\rimport java.util.HashMap;\rimport java.util.List;\r\rpublic class PhyConfigLoader {\r\r private static final Logger log = LoggerFactory.getLogger(PhyConfigLoader.class);\r\r public final static String NODE_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-node-resource.json";\r public final static String LINK_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-link-resource.json";\r public final static String EXTERNAL_NETWORK_MAC_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-external-resource.json";\r public final static String HOST_PROPERTY = "etc/opendaylight/karaf/nemo-openflow-renderer-host-resource.json";\r\r private final static String NODES = "node";\r private final static String NODE_ID = "node-id";\r private final static String NODE_TYPE = "node-type";\r\r private final static String PORTS = "port";\r private final static String PORT_ID = "port-id";\r private final static String PORT_TYPE = "port-type";\r private final static String PORT_IP = "port-ip-address";\r private final static String PORT_MAC = "port-mac-address";\r\r private final static String LINKS = "link";\r private final static String LINK_ID = "link-id";\r private final static String SRC_NODE_ID = "left-node-id";\r private final static String SRC_PORT_ID = "left-port-id";\r private final static String DST_NODE_ID = "right-node-id";\r private final static String DST_PORT_ID = "right-port-id";\r private final static String BANDWIDTH = "link-bandwidth";\r private final static String METRIC = "metric";\r\r\r private final static String HOSTS = "host";\r private final static String HOST_NAME = "name";\r private final static String HOST_ID = "id";\r private final static String HOST_IPS = "ip-addresses";\r private final static String CONNECTOR_ID = "connector-id";\r\r private final static String EXTERNAL_NETWORK_MAC = "external-network-mac";\r\r private final static String IP_ADDRESS = "ip-address";\r private final static String MAC_ADDRESS = "mac-address";\r\r private final static String ATTRIBUTES = "attribute";\r private final static String ATTRIBUTE_NAME = "name";\r private final static String ATTRIBUTE_VALUE = "value";\r\r protected final static long DEFAULT_LINK_BANDWIDTH = 10240;\r protected final static long DEFAULT_LINK_DELAY = 1;\r protected final static short DEFAULT_LINK_LOSS_RATE = 1;\r private HashMap<PhysicalNodeId, PhysicalNode> physicalNodeHashMap;\r private HashMap<PhysicalPortId, PhysicalPort> physicalPortHashMap;\r private HashMap<PhysicalLinkId, PhysicalLink> physicalLinkHashMap;\r private Table<PhysicalNodeId, PhysicalPortId, MacAddress> externalNetworkMac;\r// final private DataBroker dataProvider;\r\r private ObjectMapper objectMapper = null;\r private DataBrokerAdapter dataBrokerAdapter = null;\r\r\r\r public PhyConfigLoader(DataBroker dataBroker) {\r physicalNodeHashMap = new HashMap<PhysicalNodeId, PhysicalNode>();\r physicalPortHashMap = new HashMap<PhysicalPortId, PhysicalPort>();\r physicalLinkHashMap = new HashMap<PhysicalLinkId, PhysicalLink>();\r externalNetworkMac = HashBasedTable.create();\r\r this.objectMapper = new ObjectMapper();\r this.dataBrokerAdapter = new DataBrokerAdapter(dataBroker);\r\r loadNodesPorts();\r loadLinks();\r loadHosts();\r loadExternals();\r }\r\r public Table<PhysicalNodeId, PhysicalPortId, MacAddress> getExternalNetworkMac() {\r return externalNetworkMac;\r }\r protected PhysicalNode getPhysicalNode(PhysicalNodeId physicalNodeId){\r return physicalNodeHashMap.get(physicalNodeId);\r }\r protected PhysicalPort getPhysicalPort(PhysicalPortId physicalPortId){\r return physicalPortHashMap.get(physicalPortId);\r }\r protected PhysicalLink getPhysicalLink(PhysicalLinkId physicalLinkId){\r return physicalLinkHashMap.get(physicalLinkId);\r }\r private void loadNodesPorts() {\r String nodesStr = Utils.readFile(NODE_PROPERTY);\r try {\r JsonNode nodeRoot = objectMapper.readTree(nodesStr);\r List<PhysicalNode> physicalNodes = buildNodes(nodeRoot);\r for (PhysicalNode physicalNode : physicalNodes) {\r physicalNodeHashMap.put(physicalNode.getNodeId(), physicalNode);\r for (PhysicalPort physicalPort : physicalNode.getPhysicalPort()) {\r physicalPortHashMap.put(physicalPort.getPortId(), physicalPort);\r }\r }\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception;",e);\r }\r }\r\r private void loadLinks() {\r String linkStr = Utils.readFile(LINK_PROPERTY);\r try {\r JsonNode linkRoot = objectMapper.readTree(linkStr);\r List<PhysicalLink> physicalLinks = buildLinks(linkRoot);\r for (PhysicalLink physicalLink : physicalLinks) {\r physicalLinkHashMap.put(physicalLink.getLinkId(), physicalLink);\r }\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception;",e);\r }\r }\r\r private void loadExternals() {\r String externalStr = Utils.readFile(EXTERNAL_NETWORK_MAC_PROPERTY);\r try {\r JsonNode externalRoot = objectMapper.readTree(externalStr);\r buildExternals(externalRoot);\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception;",e);\r }\r }\r\r private void loadHosts() {\r String hostStr = Utils.readFile(HOST_PROPERTY);\r try {\r JsonNode hostRoot = objectMapper.readTree(hostStr);\r List<PhysicalHost> physicalHosts = buildHosts(hostRoot);\r for (PhysicalHost physicalHost : physicalHosts) {\r dataBrokerAdapter.addPhysicalHost(physicalHost);\r }\r } catch (IOException e) {\r // TODO Auto-generated catch block\r log.error("Exception;",e);\r }\r }\r\r private void buildExternals(JsonNode externalRoot) {\r JsonNode exNetworkNodes = externalRoot.path(EXTERNAL_NETWORK_MAC);\r log.debug("Build external network mac : {} .", exNetworkNodes);\r for (int i = 0; i < exNetworkNodes.size(); i++) {\r log.debug("Build external network execution body");\r JsonNode exNetworkNode = exNetworkNodes.get(i);\r buildExNetwork(exNetworkNode);\r }\r }\r private void buildExNetwork(JsonNode exNetwork){\r String nodeId = exNetwork.get(NODE_ID).asText();\r String portId = exNetwork.get(PORT_ID).asText();\r String peerMac = exNetwork.get(MAC_ADDRESS).asText();\r PhysicalNodeId accessNodeId = new PhysicalNodeId(nodeId);\r PhysicalPortId accessPortId = new PhysicalPortId(portId);\r MacAddress macAddress = new MacAddress(peerMac);\r externalNetworkMac.put(accessNodeId,accessPortId,macAddress);\r }\r\r private List<PhysicalNode> buildNodes(JsonNode nodesRoot) {\r List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>();\r JsonNode nodes = nodesRoot.path(NODES);\r log.debug("Build nodes: {} .", nodes);\r for (int i = 0; i < nodes.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode node = nodes.get(i);\r PhysicalNode phyNode = buildNode(node);\r if (phyNode != null) {\r physicalNodes.add(phyNode);\r }\r }\r return physicalNodes;\r }\r\r private PhysicalNode buildNode(JsonNode node) {\r PhysicalNodeBuilder nodeBuilder = new PhysicalNodeBuilder();\r\r String node_id = node.get(NODE_ID).asText();\r if (node_id.equals(""))\r return null;\r nodeBuilder.setNodeId(new PhysicalNodeId(node_id));\r PhysicalNodeKey key = new PhysicalNodeKey(nodeBuilder.getNodeId());\r nodeBuilder.setKey(key);\r\r String strType = node.get(NODE_TYPE).asText();\r PhysicalNodeInstance.NodeType nodeType = Utils.getNodeType(strType);\r nodeBuilder.setNodeType(nodeType);\r\r JsonNode ports = node.path(PORTS);\r List<PhysicalPort> phyPortList = buildPorts(ports);\r nodeBuilder.setPhysicalPort(phyPortList);\r\r JsonNode attributes = node.path(ATTRIBUTES);\r nodeBuilder.setAttribute(buildNodeAttributes(attributes));\r\r return nodeBuilder.build();\r }\r\r private List<PhysicalPort> buildPorts(JsonNode ports) {\r List<PhysicalPort> phyPortList = new ArrayList<PhysicalPort>();\r for (int j = 0; j < ports.size(); j++) {\r //JsonNode port = portIt.next();\r JsonNode port = ports.get(j);\r PhysicalPort physicalPort = buildPort(port);\r if (physicalPort != null) {\r phyPortList.add(physicalPort);\r }\r }\r return phyPortList;\r }\r\r private PhysicalPort buildPort(JsonNode port) {\r PhysicalPortBuilder physicalPortBuilder = new PhysicalPortBuilder();\r\r String strPortId = port.get(PORT_ID).asText();\r physicalPortBuilder.setPortId(new PhysicalPortId(strPortId));\r\r String strType = port.get(PORT_TYPE).asText();\r PhysicalPortInstance.PortType portType = Utils.getPortType(strType);\r physicalPortBuilder.setPortType(portType);\r\r// String strMac = port.get(PORT_MAC).asText();\r// MacAddress macAddress = new MacAddress(strMac);\r// physicalPortBuilder.setMacAddress(macAddress);\r//\r// long bandWidth = port.get(BANDWIDTH).asLong();\r// physicalPortBuilder.setBandwidth(bandWidth);\r\r JsonNode portAttributes = port.path(ATTRIBUTES);\r List<Attribute> attributes = buildPortAttributes(portAttributes);\r physicalPortBuilder.setAttribute(attributes);\r\r return physicalPortBuilder.build();\r }\r\r private List<Attribute> buildPortAttributes(JsonNode attributes) {\r List<Attribute> attributeList = new ArrayList<Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r Attribute attribute = buildPortAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private Attribute buildPortAttribute(JsonNode attribute) {\r AttributeBuilder attributeBuilder = new AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> buildNodeAttributes(JsonNode attributes) {\r List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute> attributeList =\r new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute>();\r for (int i = 0; i < attributes.size(); i++) {\r log.debug("build physical port attribute execution body.");\r JsonNode portAttribute = attributes.get(i);\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute attribute = buildNodeAttribute(portAttribute);\r if (attribute != null) {\r attributeList.add(attribute);\r }\r }\r return attributeList;\r }\r\r private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.Attribute buildNodeAttribute(JsonNode attribute) {\r org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder attributeBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeBuilder();\r String strName = attribute.path(ATTRIBUTE_NAME).asText();\r if (strName.equals("")) {\r return null;\r }\r attributeBuilder.setAttributeName(new AttributeName(strName));\r AttributeValueBuilder attributeValueBuilder = new AttributeValueBuilder();\r String strValue = attribute.path(ATTRIBUTE_VALUE).asText();\r attributeValueBuilder.setStringValue(strValue);\r attributeBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.node.instance.AttributeKey(attributeBuilder.getAttributeName()));\r attributeBuilder.setAttributeValue(attributeValueBuilder.build());\r return attributeBuilder.build();\r }\r\r\r private List<PhysicalLink> buildLinks(JsonNode linksRoot) {\r List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>();\r JsonNode links = linksRoot.path(LINKS);\r log.debug("Build links: {} .", links);\r for (int i = 0; i < links.size(); i++) {\r log.debug("build physical node execution body");\r JsonNode link = links.get(i);\r PhysicalLink phyLink = buildLink(link);\r if (phyLink != null) {\r physicalLinks.add(phyLink);\r }\r }\r return physicalLinks;\r }\r\r private PhysicalLink buildLink(JsonNode linkNode) {\r PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder();\r\r String strLinkId = linkNode.get(LINK_ID).asText();\r long metric = linkNode.get(METRIC).asLong();\r\r linkBuilder.setLinkId(new PhysicalLinkId(strLinkId));\r linkBuilder.setMetric(metric);\r\r linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH);\r linkBuilder.setDelay(DEFAULT_LINK_DELAY);\r linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE);\r\r return linkBuilder.build();\r }\r\r private List<PhysicalHost> buildHosts(JsonNode hostsNode) {\r List<PhysicalHost> physicalHosts = new ArrayList<PhysicalHost>();\r JsonNode hosts = hostsNode.path(HOSTS);\r log.debug("Build hosts: {} .", hosts);\r for (int i = 0; i < hosts.size(); i++) {\r JsonNode host = hosts.get(i);\r PhysicalHost physicalHost = buildHost(host);\r if (physicalHost != null) {\r physicalHosts.add(physicalHost);\r }\r }\r return physicalHosts;\r }\r\r private PhysicalHost buildHost(JsonNode hostNode) {\r PhysicalHostBuilder hostBuilder = new PhysicalHostBuilder();\r hostBuilder.setHostId(new PhysicalHostId(hostNode.get(HOST_ID).asText()));\r hostBuilder.setKey(new PhysicalHostKey(hostBuilder.getHostId()));\r hostBuilder.setHostName(new PhysicalHostName(hostNode.get(HOST_NAME).asText()));\r\r IpAddressesBuilder IpAddrBuilder = new IpAddressesBuilder();\r List<IpAddress> ipList = new ArrayList<IpAddress>();\r\r JsonNode ipaddrs = hostNode.path(HOST_IPS);\r for (int p = 0; p < ipaddrs.size(); p++) {\r JsonNode ipaddr = ipaddrs.get(p);\r IpAddress ip = new IpAddress(new Ipv4Address(ipaddr.get(IP_ADDRESS).asText()));\r ipList.add(ip);\r }\r\r IpAddrBuilder.setIpAddress(ipList);\r hostBuilder.setIpAddresses(IpAddrBuilder.build());\r MacAddress mac = new MacAddress(hostNode.get(MAC_ADDRESS).asText());\r hostBuilder.setMacAddress(mac);\r hostBuilder.setNodeId(new PhysicalNodeId(hostNode.get(NODE_ID).asText()));\r hostBuilder.setPortId(new PhysicalPortId(hostNode.get(CONNECTOR_ID).asText()));\r\r return hostBuilder.build();\r }\r\r\r public void close() {\r physicalLinkHashMap.clear();\r physicalPortHashMap.clear();\r physicalNodeHashMap.clear();\r externalNetworkMac.clear();\r }\r\r\r}\r
\ No newline at end of file
try {
downLatch.await();
} catch (InterruptedException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
return flowCapableNodeConnector[0];
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Created by hj on 11/5/15.
*/
public class Utils {
-
+ private static final Logger log = LoggerFactory.getLogger(Utils.class);
protected static PhysicalNodeInstance.NodeType getNodeType(String strType){
switch (strType){
case "switch":
}
reader.close();
}catch(IOException e){
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error("Exception:",e);
}
}
}
* Created by hj on 12/9/15.
*/
public class CmdExecutor {
+ private static Logger log = LoggerFactory.getLogger(CmdExecutor.class);
private static Connection sshConnection;
private static String strHostName = Config.getHostName();
private static String strUserName = Config.getHostUser();
return true;
}
} catch (IOException objException) {
- objException.printStackTrace();
+// objException.printStackTrace();
+ log.error(objException);
if (null != sshConnection) {
sshConnection.close();
sshConnection = null;
return result;
} catch (IOException objException) {
- objException.printStackTrace();
+// objException.printStackTrace();
+ log.error(objException);
} finally {
if (null != session) {
session.close();
* Created by hj on 12/9/15.
*/
public class EasyCli {
+ private static Logger log = LoggerFactory.getLogger(EasyCli.class);
private Shell shell;
public EasyCli(String prompt,String hint,Object handler){
try {
shell.commandLoop();
} catch (IOException e) {
- e.printStackTrace();
+ log.error(e);
}
}
}
* Created by hj on 12/8/15.
*/
public class Cache extends Host {
+ private static Logger log = LoggerFactory.getLogger(Cache.class);
public Cache(String name,String uuId) {
super(NodeType.CACHE,name, uuId);
}
try {
CmdExecutor.sshExecute("ip netns del " + getName());
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
}
* Created by hj on 12/8/15.
*/
public class Firewall extends Host {
+ private static Logger log = LoggerFactory.getLogger(Firewall.class);
public Firewall(String name,String uuId) {
super(NodeType.FIREWALL, name,uuId);
}
try {
CmdExecutor.sshExecute("ip netns del " + getName());
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
}
* Created by hj on 12/8/15.
*/
public class Link {
+ private static Logger log = LoggerFactory.getLogger(Link.class);
private final Connector srcInterface;
private final Connector dstInterface;
try {
CmdExecutor.sshExecute(linkAddCmd);
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
try {
CmdExecutor.sshExecute(linkDelCmd);
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
root.put("node", nodeArray);
return root;
} catch (JSONException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
return null;
}
nodeJson.put("port", ports);
return nodeJson;
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
return null;
}
root.put("external-network-mac", externalMacs);
return root;
} catch (JSONException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
return null;
}
root.put("host", hostArray);
return root;
} catch (JSONException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
return null;
}
}
root.put("link", linkArray);
} catch (JSONException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
return null;
}
return root;
linkNode.put("loss-rate", "");
return linkNode;
} catch (JSONException e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
return null;
CmdExecutor.sshExecute(command);
} catch (Exception e) {
log.error("Error while execute [{}].", command, name, nodeType);
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
}
* Created by hj on 12/8/15.
*/
public class VirtualMachine extends Host {
+ private static Logger log = LoggerFactory.getLogger(VirtualMachine.class);
public VirtualMachine(String name,String uuId) {
super(NodeType.VM, name,uuId);
}
try {
CmdExecutor.sshExecute("ip netns del " + getName());
} catch (Exception e) {
- e.printStackTrace();
+ // TODO Auto-generated catch block
+ log.error(e);
}
}
}
* Created by hj on 12/11/15.
*/
public class FileUtils {
+ private static Logger log = LoggerFactory.getLogger(FileUtils.class);
public static void write(String path, String content) {
try {
File f = new File(path);
output.write(content);
output.close();
} catch (Exception e) {
- e.printStackTrace();
+ log.error(e);
}
}
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Huawei, 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.nemo.tool.sandbox;
-
-import junit.framework.TestCase;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-import asg.cliche.Command;
-import asg.cliche.Shell;
-import asg.cliche.ShellDependent;
-import static org.mockito.Mockito.*;
-/**
- * Created by zhangmeng on 2016/1/14.
- */
-public class CliTest extends TestCase {
- private Cli cli;
- @Before
- public void setUp() throws Exception {
- cli = new Cli();
- }
-
- @Test
- public void testCliSetShell() throws Exception {
- Shell shell = mock(Shell.class);
- cli.cliSetShell(shell);
- }
-
- @Test
- public void testInstall() throws Exception {
- cli.install();
- }
-
- @Test
- public void testUninstall() throws Exception {
- cli.uninstall();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Huawei, 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.nemo.tool.sandbox;
-
-import junit.framework.TestCase;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.awt.color.CMMException;
-
-import static org.junit.Assert.*;
-import ch.ethz.ssh2.Connection;
-import ch.ethz.ssh2.Session;
-import ch.ethz.ssh2.StreamGobbler;
-import org.junit.runner.RunWith;
-import org.opendaylight.nemo.tool.sandbox.utils.Config;
-import org.opendaylight.nemo.tool.sandbox.utils.FileUtils;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.api.support.membermodification.MemberModifier;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import static org.mockito.Mockito.*;
-/**
- * Created by zhangmeng on 2016/1/14.
- */
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(ch.ethz.ssh2.Connection.class)
-public class CmdExecutorTest extends TestCase {
- private CmdExecutor cmdExecutor;
- private Class<CmdExecutor> class1;
- private Field field_sshConnection;
- @Before
- public void setUp() throws Exception {
- class1 = CmdExecutor.class;
- field_sshConnection = class1.getDeclaredField("sshConnection");
- field_sshConnection.setAccessible(true);
-
- cmdExecutor = new CmdExecutor();
- }
-
- @Test
- public void testOpen() throws Exception {
- String command = "cd ~";
- Session session = mock(Session.class);
- Connection sshConnection = mock(Connection.class);
-
- Assert.assertTrue(CmdExecutor.open() == false);
- PowerMockito.whenNew(Connection.class).withArguments(any(String.class)).thenReturn(sshConnection);
- when(sshConnection.authenticateWithPassword(any(String.class), any(String.class))).thenReturn(true);
- Assert.assertTrue(CmdExecutor.open() == false);
-// Assert.assertTrue(field_sshConnection.get(class1) == sshConnection);
-// verify(sshConnection).authenticateWithPassword(any(String.class), any(String.class));
-
- field_sshConnection.set(class1, sshConnection);
- when(sshConnection.openSession()).thenReturn(session);
- doNothing().when(session).execCommand(command);
- when(session.getStdout()).thenReturn(mock(InputStream.class));
- Assert.assertTrue(CmdExecutor.sshExecute(command) != null);
- verify(session).getStdout();
- CmdExecutor.queryInterfaceMac("eth0");
- CmdExecutor.queryInterfaceMac("1","eth0");
-
- CmdExecutor.close();
- }
-
- @Test
- public void testgetMacFromResult() throws Exception {
- Method method = class1.getDeclaredMethod("getMacFromResult",new Class[]{
- String.class
- });
- method.setAccessible(true);
- Assert.assertTrue(method.invoke(class1,"HWaddr") != null);
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Huawei, 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.nemo.tool.sandbox;
-
-import junit.framework.TestCase;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-import asg.cliche.Shell;
-import asg.cliche.ShellFactory;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import static org.mockito.Mockito.*;
-
-/**
- * Created by zhangmeng on 2016/1/14.
- */
-public class EasyCliTest extends TestCase {
- private EasyCli easyCli;
- @Before
- public void setUp() throws Exception {
- easyCli = new EasyCli("1","2","3");
- }
-
- @Test
- public void testAdd() throws Exception {
- easyCli.add("4");
- }
-
- @Test
- public void testRun() throws Exception {
- Field field = EasyCli.class.getDeclaredField("shell");
- field.setAccessible(true);
-
- Shell shell = mock(Shell.class);
-
- field.set(easyCli,shell);
- doNothing().when(shell).commandLoop();
- easyCli.run();
- verify(shell).commandLoop();
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Huawei, 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.nemo.tool.sandbox;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-import org.json.JSONObject;
-import org.junit.runner.RunWith;
-import org.opendaylight.nemo.tool.sandbox.models.*;
-import org.opendaylight.nemo.tool.sandbox.utils.PropertyLoader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.api.support.membermodification.MemberModifier;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.*;
-/**
- * Created by zhangmeng on 2016/1/14.
- */
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(CmdExecutor.class)
-public class SandBoxManagerTest extends TestCase {
- private SandBoxManager sandBoxManager;
- private Method method;
- @Before
- public void setUp() throws Exception {
- sandBoxManager = SandBoxManager.getInstance();
- }
-
- @Test
- public void testGetInstance() throws Exception {
- sandBoxManager = SandBoxManager.getInstance();
- }
-
- @Test
- public void testGets() throws Exception {
- Field field = SandBoxManager.class.getDeclaredField("network");
- field.setAccessible(true);
-
- Network network = mock(Network.class);
- JSONObject jsonObject = mock(JSONObject.class);
-
- //no powermock and network=null
- field.set(sandBoxManager, null);
- org.junit.Assert.assertTrue(!sandBoxManager.createNetwork(null));
- org.junit.Assert.assertTrue(!sandBoxManager.createNetwork());
- org.junit.Assert.assertTrue(sandBoxManager.getHosts() == null);
- org.junit.Assert.assertTrue(sandBoxManager.getExternals() == null);
- org.junit.Assert.assertTrue(sandBoxManager.getSwitches() == null);
- org.junit.Assert.assertTrue(sandBoxManager.getLinks() == null);
- org.junit.Assert.assertTrue(sandBoxManager.destroyNetwork());
-
- field.set(sandBoxManager, network);
- PowerMockito.mockStatic(CmdExecutor.class);
- PowerMockito.when(CmdExecutor.open()).thenReturn(true);
- when(network.hostJsonNode()).thenReturn(jsonObject);
- when(network.externalJsonNode()).thenReturn(jsonObject);
- when(network.nodeJsonNode()).thenReturn(jsonObject);
- when(network.innerLinkJsonNode()).thenReturn(jsonObject);
- when(network.execute(any(String.class), any(String.class))).thenReturn("test");
- org.junit.Assert.assertTrue(sandBoxManager.execute("1","1").equals("test"));
- org.junit.Assert.assertTrue(sandBoxManager.getHosts() != null);
- org.junit.Assert.assertTrue(sandBoxManager.getExternals() != null);
- org.junit.Assert.assertTrue(sandBoxManager.getSwitches() != null);
- org.junit.Assert.assertTrue(sandBoxManager.getLinks() != null);
-
- org.junit.Assert.assertTrue(sandBoxManager.createNetwork(PropertyLoader.readLines("/Network", "Network file does not exist.")));
- org.junit.Assert.assertTrue(sandBoxManager.createNetwork());
- org.junit.Assert.assertTrue(sandBoxManager.destroyNetwork());
- }
- @Test
- public void testGetNodeType() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("getNodeType",new Class[]{String.class});
- method.setAccessible(true);
-
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Switch") == NodeType.SWITCH);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Router") == NodeType.ROUTER);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Cache") == NodeType.CACHE);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Firewall") == NodeType.FIREWALL);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "Vm") == NodeType.VM);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,"1") == NodeType.UNKNOWN);
-
- }
-
- @Test
- public void testHandleLink() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("handleLink",new Class[]{String.class});
- method.setAccessible(true);
-
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, "12") == null);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,"1,2,3,4,5") != null);
- }
-
- @Test
- public void testSaveConnector() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("saveConnector",new Class[]{
- Connector.class,
- Map.class
- });
- method.setAccessible(true);
-
- Connector connector = mock(Connector.class);
- Map<String, List<Connector>> connectorMap = mock(Map.class);
-
- when(connector.getNodeName()).thenReturn("test");
- when(connectorMap.containsKey(any(String.class)))
- .thenReturn(true)
- .thenReturn(false);
- when(connectorMap.get(any(String.class))).thenReturn(mock(List.class));
- method.invoke(sandBoxManager, connector, connectorMap);
- method.invoke(sandBoxManager, connector, connectorMap);
- verify(connectorMap,times(2)).containsKey(any(String.class));
- }
-
- @Test
- public void testParserHost() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("parserHost",new Class[]{
- String[].class,
- Map.class,
- Host.class
- });
- method.setAccessible(true);
-
- String[] args = {"1","2","3","1:2"};
- Map<String, List<Connector>> connectorMap = mock(Map.class);
- Host host = mock(Host.class);
- Connector connector = mock(Connector.class);
- List<Connector> connectors = new ArrayList<Connector>();
-
- connectors.add(connector);
-
- when(host.getName()).thenReturn("test");
- when(connectorMap.get(host.getName())).thenReturn(connectors);
-
- method.invoke(sandBoxManager, args, connectorMap, host);
- verify(host,times(2)).getName();
- }
-
- @Test
- public void testHandleFirewall() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("handleFirewall",new Class[]{
- String.class,
- Map.class
- });
- method.setAccessible(true);
-
- String line = "test";
- Map<String, List<Connector>> connectorMap = mock(Map.class);
-
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null);
- line = "1,2,3,1:2";
- when(connectorMap.get(any(String.class))).thenReturn(null);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null);
- }
-
- @Test
- public void testHandleCache() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("handleCache",new Class[]{
- String.class,
- Map.class
- });
- method.setAccessible(true);
-
- String line = "test";
- Map<String, List<Connector>> connectorMap = mock(Map.class);
-
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null);
- line = "1,2,3,1:2";
- when(connectorMap.get(any(String.class))).thenReturn(null);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null);
-
- }
-
- @Test
- public void testHandleVirtualMachine() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("handleVirtualMachine",new Class[]{
- String.class,
- Map.class
- });
- method.setAccessible(true);
-
- String line = "test";
- Map<String, List<Connector>> connectorMap = mock(Map.class);
-
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) == null);
- line = "1,2,3,1:2";
- when(connectorMap.get(any(String.class))).thenReturn(null);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager,line,connectorMap) != null);
- }
-
- @Test
- public void testHandleSwitch() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("handleSwitch",new Class[]{
- String.class,
- Map.class
- });
- method.setAccessible(true);
-
- List<Connector> connectorList = new ArrayList<Connector>();
- Connector connector = mock(Connector.class);
- String line = "test";
- Map<String, List<Connector>> connectorMap = mock(Map.class);
-
- connectorList.add(connector);
-
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, line, connectorMap) == null);
- line = "Router,2,3";
- when(connectorMap.get(any(String.class))).thenReturn(connectorList);
- org.junit.Assert.assertTrue(method.invoke(sandBoxManager, line, connectorMap) != null);
-
- }
-
- @Test
- public void testGenerateNetwork() throws Exception {
- method = SandBoxManager.class.getDeclaredMethod("generateNetwork",new Class[]{List.class});
- method.setAccessible(true);
-
- List<String> list = new ArrayList<String>();
- list.add("Switch");
- method.invoke(sandBoxManager, list);
- list.clear();
- list.add("Vm");
- method.invoke(sandBoxManager, list);
- list.clear();
- list.add("Cache");
- method.invoke(sandBoxManager, list);
- list.clear();
- list.add("Firewall");
- method.invoke(sandBoxManager, list);
-
- }
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-import org.junit.runner.RunWith;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.api.support.membermodification.MemberMatcher;\r
-import org.powermock.api.support.membermodification.MemberModifier;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Field;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({CmdExecutor.class})\r
-public class CacheTest extends TestCase {\r
- String name,uuId;\r
- Cache cacheTest;\r
- private Method method;\r
- private Class class1;\r
- private Connector connector;\r
-\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- name = new String("name1");\r
- uuId = new String("11111111-1111-1111-1111-111111111111");\r
- cacheTest = new Cache(name,uuId);\r
- class1 = Cache.class;\r
- org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class);\r
- cacheTest.addConnectors(connector);\r
- }\r
-\r
- @Test\r
- public void testGenerateCommands() throws Exception {\r
- method = class1.getDeclaredMethod("generateCommands",new Class[]{});\r
- method.setAccessible(true);\r
- Assert.assertNotNull(method.invoke(cacheTest));\r
- }\r
-\r
- @Test\r
- public void testUninstall() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- cacheTest.uninstall();\r
-\r
- }\r
-\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.nemo.tool.sandbox.models.Connector;\r
-\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-public class ConnectorTest extends TestCase {\r
- private int order;\r
- private String nodeName;\r
- private Connector connectorTest;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- order = 10;\r
- nodeName = "connector";\r
- connectorTest = new Connector(nodeName,order);\r
-\r
- }\r
-\r
- @Test\r
- public void testGetConnectorName() throws Exception {\r
- Assert.assertNotNull(connectorTest.getConnectorName());\r
- }\r
-\r
- @Test\r
- public void testGetOrder() throws Exception {\r
- Assert.assertNotNull(connectorTest.getOrder());\r
- }\r
-\r
- @Test\r
- public void testGetNodeName() throws Exception {\r
- Assert.assertNotNull(connectorTest.getNodeName());\r
- }\r
-\r
- @Test\r
- public void testEquals() throws Exception {\r
- Assert.assertNotNull(connectorTest.equals(this));\r
-\r
- }\r
-\r
- @Test\r
- public void testHashCode() throws Exception {\r
- Assert.assertNotNull(connectorTest.hashCode());\r
- }\r
-\r
- @Test\r
- public void testToString() throws Exception {\r
- Assert.assertNotNull(connectorTest.toString());\r
- }\r
-\r
- @Test\r
- public void testCompareTo() throws Exception {\r
- Assert.assertNotNull(connectorTest.compareTo(new Connector("connector2",5)));\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-import org.junit.runner.RunWith;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.api.support.membermodification.MemberMatcher;\r
-import org.powermock.api.support.membermodification.MemberModifier;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-import org.opendaylight.nemo.tool.sandbox.models.Firewall;\r
-\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Field;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({CmdExecutor.class})\r
-public class FirewallTest extends TestCase {\r
-\r
- String name,uuId;\r
- Firewall firewallTest;\r
- private Method method;\r
- private Class class1;\r
- private Connector connector;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- name = new String("name1");\r
- uuId = new String("11111111-1111-1111-1111-111111111111");\r
- firewallTest = new Firewall(name,uuId);\r
- class1 = Firewall.class;\r
- org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class);\r
- firewallTest.addConnectors(connector);\r
-\r
- }\r
-\r
- @Test\r
- public void testGenerateCommands() throws Exception {\r
- method = class1.getDeclaredMethod("generateCommands",new Class[]{});\r
- method.setAccessible(true);\r
- Assert.assertNotNull(method.invoke(firewallTest));\r
-\r
- }\r
-\r
- @Test\r
- public void testUninstall() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- firewallTest.uninstall();\r
-\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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.nemo.tool.sandbox.models;\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-import org.opendaylight.nemo.tool.sandbox.models.Connector;\r
-\r
-import org.junit.runner.RunWith;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.api.support.membermodification.MemberMatcher;\r
-import org.powermock.api.support.membermodification.MemberModifier;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({CmdExecutor.class})\r
-public class LinkTest extends TestCase {\r
-\r
- private Connector srcInterface;\r
- private Connector dstInterface;\r
- private Link likeTest;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- srcInterface = new Connector("src",1);\r
- dstInterface = new Connector("dst",2);\r
- likeTest = new Link(srcInterface,dstInterface);\r
-\r
- }\r
-\r
- @Test\r
- public void testGetSrcConnector() throws Exception {\r
- Assert.assertNotNull(likeTest.getSrcConnector());\r
- }\r
-\r
- @Test\r
- public void testGetDstConnector() throws Exception {\r
- Assert.assertNotNull(likeTest.getDstConnector());\r
- }\r
-\r
- @Test\r
- public void testInstall() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- likeTest.install();\r
- }\r
-\r
- @Test\r
- public void testUninstall() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- likeTest.uninstall();\r
- }\r
-\r
- @Test\r
- public void testEquals() throws Exception {\r
- Assert.assertNotNull(likeTest.equals(this));\r
- }\r
-\r
- @Test\r
- public void testHashCode() throws Exception {\r
- Assert.assertNotNull(likeTest.hashCode());\r
- }\r
-\r
- @Test\r
- public void testToString() throws Exception {\r
- Assert.assertNotNull(likeTest.toString());\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-import org.opendaylight.nemo.tool.sandbox.models.Cache;\r
-import org.opendaylight.nemo.tool.sandbox.models.Connector;\r
-import org.opendaylight.nemo.tool.sandbox.models.Network;\r
-\r
-import org.junit.runner.RunWith;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.api.support.membermodification.MemberMatcher;\r
-import org.powermock.api.support.membermodification.MemberModifier;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-\r
-import org.json.JSONArray;\r
-import org.json.JSONException;\r
-import org.json.JSONObject;\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-import org.opendaylight.nemo.tool.sandbox.utils.Config;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({CmdExecutor.class})\r
-public class NetworkTest extends TestCase {\r
- private Network networkTest;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- networkTest = new Network();\r
-\r
- }\r
-\r
- @Test\r
- public void testAddHost() throws Exception {\r
- networkTest.addHost(new Cache("src1","1"));\r
- networkTest.addHost(new Cache("dst2","1"));\r
- }\r
-\r
- @Test\r
- public void testAddSwitch() throws Exception {\r
- networkTest.addSwitch(new Switch("dst1", 1L));\r
- networkTest.addSwitch(new Switch("src2", 1L));\r
- networkTest.addSwitch(new Switch("src3", 1L));\r
- networkTest.addSwitch(new Switch("dst3", 1L));\r
- }\r
-\r
- @Test\r
- public void testAddLink() throws Exception {\r
- networkTest.addLink(new Link(new Connector("src1", 1), new Connector("dst1", 2)));\r
- networkTest.addLink(new Link(new Connector("src2", 1), new Connector("dst2", 2)));\r
- networkTest.addLink(new Link(new Connector("src3", 1), new Connector("dst3", 2)));\r
-\r
- }\r
-\r
- @Test\r
- public void testExecute() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.open()).thenReturn(true);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.doNothing().when(CmdExecutor.class);\r
- CmdExecutor.close();\r
- Assert.assertNotNull(networkTest.execute("cache", "command"));\r
-\r
- }\r
-\r
- @Test\r
- public void testInstall() throws Exception {\r
- //test traversal\r
- networkTest.install();\r
-\r
- }\r
-\r
- @Test\r
- public void testUninstall() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
-\r
- networkTest.uninstall();\r
-\r
- }\r
-\r
- @Test\r
- public void testEchoConfig() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
-\r
- networkTest.echoConfig();\r
-\r
- //test hostJsonNode()\r
-\r
-\r
-\r
- }\r
-\r
- @Test\r
- public void testInnerLinkJsonNode() throws Exception {\r
-\r
- Assert.assertNotNull(networkTest.innerLinkJsonNode());\r
-\r
-\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-public class RouterTest extends TestCase {\r
- private String name;\r
- private long dataPathId;\r
- private Router routerTest;\r
- @Before\r
- public void setUp() throws Exception {\r
-\r
- }\r
-\r
- @Test\r
- public void test1() throws Exception {\r
- name = new String("name1");\r
- dataPathId = 1L;\r
- routerTest = new Router(name,dataPathId);\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-import org.opendaylight.nemo.tool.sandbox.utils.Config;\r
-import org.opendaylight.nemo.tool.sandbox.utils.HexString;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Field;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-public class SwitchTest extends TestCase {\r
-\r
- private String name;\r
- private long dataPathId;\r
- private Switch switchTest;\r
- private Class class1;\r
- private Method method;\r
-\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- name = new String("name1");\r
- dataPathId = 1L;\r
- switchTest = new Switch(name,dataPathId);\r
- class1 = Switch.class;\r
- org.opendaylight.nemo.tool.sandbox.models.Connector connector = new org.opendaylight.nemo.tool.sandbox.models.Connector("connectorname",1);\r
- switchTest.addConnectors(connector);\r
- }\r
-\r
- @Test\r
- public void testGetDataPathId() throws Exception {\r
- Assert.assertNotNull(switchTest.getDataPathId());\r
- }\r
-\r
- @Test\r
- public void testGenerateCommands() throws Exception {\r
- method = class1.getDeclaredMethod("generateCommands",new Class[]{});\r
- method.setAccessible(true);\r
- Assert.assertNotNull(method.invoke(switchTest));\r
-\r
- }\r
-\r
- @Test\r
- public void testToString() throws Exception {\r
- Assert.assertNotNull(switchTest.toString());\r
-\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*\r
- * Copyright (c) 2016 Huawei, 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
-package org.opendaylight.nemo.tool.sandbox.models;\r
-\r
-import junit.framework.TestCase;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import static org.mockito.Mockito.*;\r
-import static org.junit.Assert.*;\r
-\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-import org.opendaylight.nemo.tool.sandbox.models.VirtualMachine;\r
-\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Field;\r
-\r
-import org.junit.runner.RunWith;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.api.support.membermodification.MemberMatcher;\r
-import org.powermock.api.support.membermodification.MemberModifier;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.opendaylight.nemo.tool.sandbox.CmdExecutor;\r
-\r
-/**\r
- * Created by Thomas Liu on 2016/1/14.\r
- */\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({CmdExecutor.class})\r
-public class VirtualMachineTest extends TestCase {\r
- String name,uuId;\r
- Cache cacheTest;\r
- private VirtualMachine virtualMachineTest;\r
- private Connector connector;\r
- private Class class1;\r
- private Method method;\r
- @Before\r
- public void setUp() throws Exception {\r
- name = new String("name1");\r
- uuId = new String("11111111-1111-1111-1111-111111111111");\r
- virtualMachineTest = new VirtualMachine(name,uuId);\r
- org.opendaylight.nemo.tool.sandbox.models.Connector connector = mock(org.opendaylight.nemo.tool.sandbox.models.Connector.class);\r
- virtualMachineTest.addConnectors(connector);\r
- class1 = VirtualMachine.class;\r
-\r
- }\r
-\r
- @Test\r
- public void testGenerateCommands() throws Exception {\r
- method = class1.getDeclaredMethod("generateCommands",new Class[]{});\r
- method.setAccessible(true);\r
- Assert.assertNotNull(method.invoke(virtualMachineTest));\r
- }\r
-\r
- @Test\r
- public void testUninstall() throws Exception {\r
- PowerMockito.mockStatic(CmdExecutor.class);\r
- PowerMockito.when(CmdExecutor.sshExecute(any(String.class))).thenReturn("null");\r
- virtualMachineTest.uninstall();\r
-\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Huawei, 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.nemo.tool.sandbox.northbound;
-
-import junit.framework.TestCase;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-import org.codehaus.enunciate.jaxrs.ResponseCode;
-import org.codehaus.enunciate.jaxrs.StatusCodes;
-import org.codehaus.enunciate.jaxrs.TypeHint;
-import org.junit.runner.RunWith;
-import org.opendaylight.nemo.tool.sandbox.SandBoxManager;
-
-import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.UriInfo;
-import java.util.ArrayList;
-import java.util.List;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.api.support.membermodification.MemberMatcher;
-import org.powermock.api.support.membermodification.MemberModifier;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import static org.mockito.Mockito.*;
-/**
- * Created by zhangmeng on 2016/1/14.
- */
-
-public class SandboxNorthboundTest extends TestCase {
- private SandboxNorthbound sandboxNorthbound;
- @Before
- public void setUp() throws Exception {
- sandboxNorthbound = new SandboxNorthbound();
- }
-
- @Test
- public void testCreate() throws Exception {
- ExecuteRequest executeRequest = new ExecuteRequest();
- Assert.assertTrue(sandboxNorthbound.create(null,"test") != null);
- Assert.assertTrue(sandboxNorthbound.create(null,executeRequest) != null);
- }
-
- @Test
- public void testDestroy() throws Exception {
- Assert.assertTrue(sandboxNorthbound.destroy(null) != null);
- }
-
- @Test
- public void testGetXml() throws Exception {
- Assert.assertTrue(sandboxNorthbound.getXml() != null);
- }
-
- @Test
- public void testGetHosts() throws Exception {
- Assert.assertTrue(sandboxNorthbound.getHosts() == null);
- }
-
- @Test
- public void testGetSwitches() throws Exception {
- Assert.assertTrue(sandboxNorthbound.getSwitches() != null);
- }
-
- @Test
- public void testGetLinks() throws Exception {
- Assert.assertTrue(sandboxNorthbound.getLinks() != null);
- }
-
- @Test
- public void testGetExternals() throws Exception {
- Assert.assertTrue(sandboxNorthbound.getExternals() == null);
- }
-}
\ No newline at end of file