private void publishNodeConnectorUpdate(final Map.Entry<InstanceIdentifier<?>,DataObject> entry, final UpdateType updateType) { if (entry.getKey().getTargetType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector.class)) { NodeConnectorRef nodeConnectorRef = new NodeConnectorRef(entry.getKey()); NodeConnector nodeConnector = null; try { nodeConnector = NodeMapping.toADNodeConnector(nodeConnectorRef); } catch (ConstructionException e) { LOG.debug("Construction exception: %s",e.getMessage()); } HashSet<Property> _aDNodeConnectorProperties = NodeMapping.toADNodeConnectorProperties((org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) entry.getValue()); this.publishNodeConnectorUpdate(nodeConnector, updateType, _aDNodeConnectorProperties); } }
/** * 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; } }
@Override public Status removeStaticHostUsingIPAndMac(String networkAddress, String macAddress) { try { if ((keyScheme != null) && (keyScheme.equals(HostIdFactory.DEFAULT_IP_KEY_SCHEME))) { return new Status(StatusCode.NOTALLOWED, "Host DB Key scheme used is not IP only scheme."); } InetAddress address = InetAddress.getByName(networkAddress); DataLinkAddress mac = new EthernetAddress(HexEncode.bytesFromHexString(macAddress)); return removeStaticHostReq(address, mac); } catch (UnknownHostException e) { logger.debug("Invalid IP Address when trying to remove host", e); return new Status(StatusCode.BADREQUEST, "Invalid IP Address when trying to remove host"); } catch (ConstructionException e) { // TODO Auto-generated catch block e.printStackTrace(); return new Status(StatusCode.BADREQUEST, "Invalid Input parameters have been passed."); } }
@Override public void descriptionRefreshed(Long switchId, SNMPDescriptionStatistics descriptionStats) { Node node; try { node = new Node(/*NodeIDType.OPENFLOW*/"SNMP", switchId); } catch (ConstructionException e) { logger.error("ERROR: descriptionRefreshed(): fail to create Node with type SNMP and nodeID {}: {}", switchId, e.getMessage()); return; } Set<Property> properties = new HashSet<Property>(1); Description desc = new Description( descriptionStats.getDatapathDescription()); properties.add(desc); // Notify all internal and external listeners notifyInventoryShimListener(node, UpdateType.CHANGED, properties); }
/** * 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; }
private void removeNode(ISwitch sw) { Node node; try { node = new Node(/*NodeIDType.OPENFLOW*/"SNMP", sw.getId()); } catch (ConstructionException e) { logger.error("ERROR: removeNode(): fail to create Node with type SNMP and nodeID {}: {}", sw.getId(), e.getMessage()); return; } UpdateType type = UpdateType.REMOVED; // Notify all internal and external listeners notifyInventoryShimListener(node, type, null); }
/** * 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); }
@Override public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable( GetFlowStatisticsFromFlowTableInput input) { GetFlowStatisticsFromFlowTableOutput rpcResultType = null; boolean rpcResultBool = false; try { Node node = NodeMapping.toADNode(input.getNode()); Flow flow = ToSalConversionsUtils.toFlow(input, null); FlowOnNode readFlow = readDelegate.readFlow(node, flow); List<FlowAndStatisticsMapList> flowOnNodeToFlowStatistics = new ArrayList<FlowAndStatisticsMapList>(); flowOnNodeToFlowStatistics.add(toOdFlowStatistics(readFlow)); rpcResultType = new GetFlowStatisticsFromFlowTableOutputBuilder().setFlowAndStatisticsMapList(flowOnNodeToFlowStatistics).build(); rpcResultBool = true; } catch (ConstructionException e) { LOG.error(e.getMessage()); } return Futures.immediateFuture(RpcResultBuilder.<GetFlowStatisticsFromFlowTableOutput> status(rpcResultBool).withResult(rpcResultType).build()); }
/** * 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"); } }
node = new Node(/*NodeIDType.OPENFLOW*/"SNMP", sw.getId()); } catch (ConstructionException e) { logger.error("ERROR: addNode(): fail to create Node with type SNMP and nodeID {}: {}", sw.getId(), e.getMessage()); return;
/** * 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; }
@Override public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable( GetAllFlowStatisticsFromFlowTableInput input) { GetAllFlowStatisticsFromFlowTableOutput rpcResultType = null; boolean rpcResultBool = false; try { Node adNode = NodeMapping.toADNode(input.getNode()); List<FlowOnNode> flowsOnNode = readDelegate.readAllFlows(adNode); List<FlowAndStatisticsMapList> flowsStatistics = toOdFlowsStatistics(flowsOnNode); GetAllFlowStatisticsFromFlowTableOutputBuilder builder = new GetAllFlowStatisticsFromFlowTableOutputBuilder(); builder.setTransactionId(new TransactionId(BigInteger.ZERO)); rpcResultType = builder.setFlowAndStatisticsMapList(flowsStatistics).build(); rpcResultBool = true; } catch (ConstructionException e) { LOG.error(e.getMessage()); } return Futures.immediateFuture(RpcResultBuilder.<GetAllFlowStatisticsFromFlowTableOutput> status(rpcResultBool).withResult(rpcResultType).build()); }
/** * 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(); }
/** * Essentially this API will return the same result as getAllFlowStatisticsFromFlowTable */ @Override public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables( GetAllFlowsStatisticsFromAllFlowTablesInput input) { GetAllFlowsStatisticsFromAllFlowTablesOutput rpcResultType = null; boolean rpcResultBool = false; try { Node adNode = NodeMapping.toADNode(input.getNode()); List<FlowOnNode> flowsOnNode = readDelegate.readAllFlows(adNode); List<FlowAndStatisticsMapList> flowsStatistics = toOdFlowsStatistics(flowsOnNode); GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder builder = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder(); builder.setTransactionId(new TransactionId(BigInteger.ZERO)); rpcResultType = builder.setFlowAndStatisticsMapList(flowsStatistics).build(); rpcResultBool = true; } catch (ConstructionException e) { LOG.error(e.getMessage()); } return Futures.immediateFuture(RpcResultBuilder.<GetAllFlowsStatisticsFromAllFlowTablesOutput> status(rpcResultBool).withResult(rpcResultType).build()); }
/** * 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"); } }
rawPkt.setOutgoingNodeConnector(nodeConnector); } catch (ConstructionException cex) { logger.warn("RawPacket creation caught exception {}", cex.getMessage()); } catch (Exception e) { logger.error("Failed to serialize the LLDP packet: " + e);
/** * 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"); } }