/** * Construct the Edge * * @param tailNodeConnector Tail Node output connector * @param headNodeConnector Head Node input connector * */ public Edge(NodeConnector tailNodeConnector, NodeConnector headNodeConnector) throws ConstructionException { if (tailNodeConnector == null || headNodeConnector == null) { throw new ConstructionException( "Null tail or head NodeConnector supplied"); } else { this.tailNodeConnector = tailNodeConnector; this.headNodeConnector = headNodeConnector; } }
/** * Create an Host representation from the combination Data Link * layer/Network layer address, both are needed to construct the * object. Fake value can also be provided in case are not * existent. * * @param dataLayerAddress Data Link Address for the host * @param networkAddress Network Address for the host * * @return the constructed object */ public Host(DataLinkAddress dataLayerAddress, InetAddress networkAddress) throws ConstructionException { if (dataLayerAddress == null) { throw new ConstructionException("Passed null datalink address"); } if (networkAddress == null) { throw new ConstructionException("Passed null network address"); } this.dataLayerAddress = dataLayerAddress; this.networkAddress = networkAddress; }
/** * Public constructor for an Ethernet MAC address starting from * the byte constituing the address, the constructor validate the * size of the arrive to make sure it met the expected size * * @param macAddress A byte array in big endian format * representing the Ethernet MAC Address * * @return The constructed object if valid */ public EthernetAddress(byte[] macAddress) throws ConstructionException { super(addressName); if (macAddress == null) { throw new ConstructionException("Null input parameter passed"); } if (macAddress.length != SIZE) { throw new ConstructionException( "Wrong size of passed byte array, expected:" + SIZE + " got:" + macAddress.length); } this.macAddress = new byte[SIZE]; System.arraycopy(macAddress, 0, this.macAddress, 0, SIZE); }
/** * Copy Construct for a path * * @param src Path to copy from * */ public Path(Path src) throws ConstructionException { if (src != null) { this.edges = new LinkedList<Edge>(src.getEdges()); } else { throw new ConstructionException("src supplied was null"); } }
/** * Constructor for RawPacket * * @param data * content of the packet as bytestream * @param e * datalink encapsulation for the packet * */ public RawPacket(byte[] data, LinkEncap e) throws ConstructionException { if (data == null) { throw new ConstructionException("Empty data"); } if (e == null) { throw new ConstructionException("Encap not known"); } this.packetData = new byte[data.length]; System.arraycopy(data, 0, this.packetData, 0, data.length); this.encap = e; this.incomingTime = new TimeStamp(System.currentTimeMillis(), "IncomingTime"); this.copyTime = null; }
/** * Copy constructor * * @param h Host to copy values from * * @return constructed copy */ public Host(Host h) throws ConstructionException { if (h == null) { throw new ConstructionException("Passed null host"); } this.dataLayerAddress = h.getDataLayerAddress(); this.networkAddress = h.getNetworkAddress(); }
/** * Copy Constructor for the Node objects. * * @param src type of nodes to copy from * */ public Node(Node src) throws ConstructionException { if (src != null) { this.nodeType = src.getType(); // Here we can reference the object because that is // supposed to be an immutable identifier as well like a // UUID/Integer and so on, hence no need to create a copy // of it this.nodeID = src.getID(); } else { throw new ConstructionException("Null incoming object to copy from"); } }
/** * Constructor for the Node objects, it validate the input so if * the ID passed is not of the type expected accordingly to the * type an exception is raised. * * @param nodeType Type of the node we are building * @param id ID used by the SDN technology to identify the node * */ public Node(String nodeType, Object id) throws ConstructionException { if (NodeIDType.getClassType(nodeType) != null && NodeIDType.getClassType(nodeType).isInstance(id)) { this.nodeType = nodeType; this.nodeID = id; } else { throw new ConstructionException("Type of incoming object:" + id.getClass() + " not compatible with expected type:" + NodeIDType.getClassType(nodeType)); } }
/** * Construct an object representing a path, the constructor will * check if the passed list of edges is such that for every * consecutive edges the head node of the first edge coincide with * the tail node of the subsequent in order for connectivity to be there. * * @param edges Edges of the path * */ public Path(List<Edge> edges) throws ConstructionException { // Lets check if the list of edges is such that the head node // of an edge is also the tail node of the subsequent one boolean sequential = true; if (edges.size() >= 2) { for (int i = 0; i < edges.size() - 1; i++) { Edge current = edges.get(i); Edge next = edges.get(i + 1); if (!current.getHeadNodeConnector().getNode().equals(next.getTailNodeConnector().getNode())) { sequential = false; break; } } } else if (edges.size() == 0) { throw new ConstructionException("Path is empty"); } if (!sequential) { throw new ConstructionException("Path is not sequential"); } this.edges = edges; }
public NodeTable(String nodeTableType, Object id, Node node) throws ConstructionException { if (NodeTableIDType.getClassType(nodeTableType) != null && NodeTableIDType.getClassType(nodeTableType).isInstance(id) && node.getType().equals(nodeTableType)) { this.nodeTableType = nodeTableType; this.nodeTableID = id; this.nodeTableNode = node; } else { throw new ConstructionException("Type of incoming object:" + id.getClass() + " not compatible with expected type:" + NodeTableIDType.getClassType(nodeTableType) + " or Node type incompatible:" + node.getType()); } }
/** * Copy Construct the Edge * * @param src Edge to copy from * */ public Edge(Edge src) throws ConstructionException { if (src != null) { this.tailNodeConnector = new NodeConnector(src .getTailNodeConnector()); this.headNodeConnector = new NodeConnector(src .getHeadNodeConnector()); } else { throw new ConstructionException("src supplied was null"); } }
/** * Create a NodeConnector from the component element. The * constructor make sure the NodeConnector type is congruent with * the Node used and also the NodeConnector ID is of type expected * * @param nodeConnectorType Type of the NodeConnector * @param id ID portion of the NodeConnector * @param node Node to which the NodeConnector is attached too * */ public NodeConnector(String nodeConnectorType, Object id, Node node) throws ConstructionException { // In case of compatible type being null then assume that this // port can be attached on any node. String compatibleNode = NodeConnectorIDType.getCompatibleNode(nodeConnectorType); if (NodeConnectorIDType.getClassType(nodeConnectorType) != null && NodeConnectorIDType.getClassType(nodeConnectorType).isInstance(id) && (compatibleNode == null || node.getType().equals(compatibleNode))) { this.nodeConnectorType = nodeConnectorType; this.nodeConnectorID = id; this.nodeConnectorNode = node; } else { throw new ConstructionException("Type of incoming object:" + id.getClass() + " not compatible with expected type:" + NodeConnectorIDType.getClassType(nodeConnectorType) + " or Node type incompatible:" + node.getType()); } }
/** * Copy Constructor for RawPacket, it performs a copy of the packet so each * packet can be modified independently without worrying that source packet * content is touched * * @param src * packet to copy data from * */ public RawPacket(RawPacket src) throws ConstructionException { if (src == null) { throw new ConstructionException("null source packet"); } if (src.getPacketData() != null) { this.packetData = new byte[src.getPacketData().length]; System.arraycopy(src.getPacketData(), 0, this.packetData, 0, src.getPacketData().length); } else { throw new ConstructionException("Empty packetData"); } this.encap = src.getEncap(); this.incomingTime = src.getIncomingTime(); this.incomingNodeConnector = src.getIncomingNodeConnector(); this.outgoingNodeConnector = src.getOutgoingNodeConnector(); this.props = (src.props == null ? null : new HashMap<Object, Object>( src.props)); this.copyTime = new TimeStamp(System.currentTimeMillis(), "CopyTime"); }
/** * Copy constructor for NodeConnector * * @param src NodeConnector to copy from * */ public NodeConnector(NodeConnector src) throws ConstructionException { if (src != null) { this.nodeConnectorType = src.getType(); // Here we can reference the object because that is // supposed to be an immutable identifier as well like a // UUID/Integer and so on, hence no need to create a copy // of it this.nodeConnectorID = src.getID(); this.nodeConnectorNode = new Node(src.getNode()); } else { throw new ConstructionException("Null incoming object to copy from"); } }
/** * Copy constructor for NodeTable * * @param src NodeTable to copy from * */ public NodeTable(NodeTable src) throws ConstructionException { if (src != null) { this.nodeTableType = src.getType(); // Here we can reference the object because that is // supposed to be an immutable identifier as well like a // UUID/Integer and so on, hence no need to create a copy // of it this.nodeTableID = src.getID(); this.nodeTableNode = new Node(src.getNode()); } else { throw new ConstructionException("Null incoming object to copy from"); } }