Search in sources :

Example 16 with NodeConnector

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector in project genius by opendaylight.

the class ArpUtilImpl method sendArpRequest.

@Override
public Future<RpcResult<Void>> sendArpRequest(SendArpRequestInput arpReqInput) {
    LOG.trace("rpc sendArpRequest invoked for ip {}", arpReqInput.getIpaddress());
    BigInteger dpnId;
    byte[] payload;
    String interfaceName = null;
    byte[] srcIpBytes;
    byte[] dstIpBytes;
    byte[] srcMac;
    RpcResultBuilder<Void> failureBuilder = RpcResultBuilder.failed();
    RpcResultBuilder<Void> successBuilder = RpcResultBuilder.success();
    try {
        dstIpBytes = getIpAddressBytes(arpReqInput.getIpaddress());
    } catch (UnknownHostException e) {
        LOG.error("Cannot get IP address", e);
        failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.UNKNOWN_IP_ADDRESS_SUPPLIED);
        return Futures.immediateFuture(failureBuilder.build());
    }
    int localErrorCount = 0;
    for (InterfaceAddress interfaceAddress : arpReqInput.getInterfaceAddress()) {
        try {
            interfaceName = interfaceAddress.getInterface();
            srcIpBytes = getIpAddressBytes(interfaceAddress.getIpAddress());
            GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName);
            checkNotNull(portResult);
            dpnId = portResult.getDpid();
            Long portid = portResult.getPortno();
            checkArgument(null != dpnId && !BigInteger.ZERO.equals(dpnId), ArpConstants.DPN_NOT_FOUND_ERROR, interfaceName);
            NodeConnectorRef ref = MDSALUtil.getNodeConnRef(dpnId, portid.toString());
            checkNotNull(ref, ArpConstants.NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName);
            LOG.trace("sendArpRequest received dpnId {} out interface {}", dpnId, interfaceName);
            if (interfaceAddress.getMacaddress() == null) {
                srcMac = MDSALUtil.getMacAddressForNodeConnector(dataBroker, (InstanceIdentifier<NodeConnector>) ref.getValue());
            } else {
                String macAddr = interfaceAddress.getMacaddress().getValue();
                srcMac = HexEncode.bytesFromHexString(macAddr);
            }
            checkNotNull(srcMac, ArpConstants.FAILED_TO_GET_SRC_MAC_FOR_INTERFACE, interfaceName, ref.getValue());
            checkNotNull(srcIpBytes, ArpConstants.FAILED_TO_GET_SRC_IP_FOR_INTERFACE, interfaceName);
            payload = ArpPacketUtil.getPayload(ArpConstants.ARP_REQUEST_OP, srcMac, srcIpBytes, ArpPacketUtil.ETHERNET_BROADCAST_DESTINATION, dstIpBytes);
            List<Action> actions = getEgressAction(interfaceName);
            sendPacketOutWithActions(dpnId, payload, ref, actions);
            LOG.trace("sent arp request for {}", arpReqInput.getIpaddress());
        } catch (UnknownHostException | PacketException | InterruptedException | ExecutionException | ReadFailedException e) {
            LOG.trace("failed to send arp req for {} on interface {}", arpReqInput.getIpaddress(), interfaceName);
            failureBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
            successBuilder.withError(ErrorType.APPLICATION, ArpConstants.FAILED_TO_SEND_ARP_REQ_FOR_INTERFACE + interfaceName, e);
            localErrorCount++;
        }
    }
    if (localErrorCount == arpReqInput.getInterfaceAddress().size()) {
        // All the requests failed
        return Futures.immediateFuture(failureBuilder.build());
    }
    return Futures.immediateFuture(successBuilder.build());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) UnknownHostException(java.net.UnknownHostException) InterfaceAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.arputil.rev160406.interfaces.InterfaceAddress) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) BigInteger(java.math.BigInteger) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) GetPortFromInterfaceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetPortFromInterfaceOutput) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with NodeConnector

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector in project genius by opendaylight.

the class InterfaceInventoryStateListener method remove.

@Override
protected void remove(InstanceIdentifier<FlowCapableNodeConnector> key, FlowCapableNodeConnector flowCapableNodeConnectorOld) {
    if (interfacemgrProvider.isItmDirectTunnelsEnabled() && interfaceManagerCommonUtils.isTunnelInternal(flowCapableNodeConnectorOld.getName())) {
        LOG.debug("ITM Direct Tunnels is enabled, ignoring node connector removed for internal tunnel {}", flowCapableNodeConnectorOld.getName());
        return;
    }
    if (!entityOwnershipUtils.isEntityOwner(IfmConstants.INTERFACE_CONFIG_ENTITY, IfmConstants.INTERFACE_CONFIG_ENTITY)) {
        return;
    }
    LOG.debug("Received NodeConnector Remove Event: {}, {}", key, flowCapableNodeConnectorOld);
    NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(key.firstIdentifierOf(NodeConnector.class)).getId();
    String portName = InterfaceManagerCommonUtils.getPortNameForInterface(nodeConnectorId, flowCapableNodeConnectorOld.getName());
    remove(nodeConnectorId, null, flowCapableNodeConnectorOld, portName, true);
}
Also used : NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)

Example 18 with NodeConnector

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector in project genius by opendaylight.

the class MDSALUtil method getNodeConnRef.

public static NodeConnectorRef getNodeConnRef(String nodeId, String port) {
    StringBuilder sb = new StringBuilder();
    sb.append(nodeId);
    sb.append(SEPARATOR);
    sb.append(port);
    String nodeConnectorKeyAsString = sb.toString();
    NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeConnectorKeyAsString);
    NodeConnectorKey nodeConnectorKey = new NodeConnectorKey(nodeConnectorId);
    NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
    InstanceIdentifierBuilder<Node> nodeInstanceIdentifierBuilder = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeKey);
    InstanceIdentifierBuilder<NodeConnector> nodeConnectorInstanceIdentifierBuilder = nodeInstanceIdentifierBuilder.child(NodeConnector.class, nodeConnectorKey);
    InstanceIdentifier<NodeConnector> nodeConnectorInstanceIdentifier = nodeConnectorInstanceIdentifierBuilder.toInstance();
    NodeConnectorRef nodeConnectorRef = new NodeConnectorRef(nodeConnectorInstanceIdentifier);
    return nodeConnectorRef;
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

Example 19 with NodeConnector

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector in project openflowplugin by opendaylight.

the class ShellUtil method getNodeInfo.

public static OFNode getNodeInfo(final Long nodeId, final DataBroker broker) {
    OFNode ofNode = null;
    ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
    InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(NODE_PREFIX + nodeId))).build();
    Optional<Node> result;
    try {
        CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
        result = checkedFuture.get();
        if (result.isPresent()) {
            Node node = result.get();
            String name = null;
            List<NodeConnector> nodeConnectors = null;
            List<String> portList = new ArrayList<>();
            FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
            if (flowCapableNode != null) {
                name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
            } else {
                LOG.error("Error while converting OFNode:{} to FlowCapableNode: {}", node.getId());
                return null;
            }
            nodeConnectors = node.getNodeConnector();
            for (NodeConnector nodeConnector : nodeConnectors) {
                FlowCapableNodeConnector flowCapableNodeConnector = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
                if (flowCapableNodeConnector == null) {
                    LOG.error("Error for OFNode:{} while reading nodeConnectors {}", node.getId());
                    return null;
                } else {
                    String portName = flowCapableNodeConnector.getName();
                    portList.add(portName);
                }
            }
            ofNode = new OFNode(nodeId, name, portList);
        } else {
            LOG.error("OFNode with nodeId {} not present Inventory DS: {}", nodeId);
            return null;
        }
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("Error reading node {} from Inventory DS: {}", nodeId, e);
    }
    return ofNode;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ArrayList(java.util.ArrayList) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ExecutionException(java.util.concurrent.ExecutionException) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 20 with NodeConnector

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector in project openflowplugin by opendaylight.

the class TerminationPointChangeListenerImpl method processRemovedTerminationPoints.

private void processRemovedTerminationPoints(final DataTreeModification<FlowCapableNodeConnector> modification) {
    final InstanceIdentifier<FlowCapableNodeConnector> removedNode = modification.getRootPath().getRootIdentifier();
    final TpId terminationPointId = provideTopologyTerminationPointId(removedNode);
    final InstanceIdentifier<TerminationPoint> iiToTopologyTerminationPoint = provideIIToTopologyTerminationPoint(terminationPointId, removedNode);
    if (iiToTopologyTerminationPoint != null) {
        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> node = iiToTopologyTerminationPoint.firstIdentifierOf(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class);
        operationProcessor.enqueueOperation(manager -> {
            Optional<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nodeOptional = Optional.empty();
            try {
                nodeOptional = Optional.ofNullable(manager.readFromTransaction(LogicalDatastoreType.OPERATIONAL, node).checkedGet().orNull());
            } catch (ReadFailedException e) {
                LOG.warn("Error occurred when trying to read NodeConnector: {}", e.getMessage());
                LOG.debug("Error occurred when trying to read NodeConnector.. ", e);
            }
            if (nodeOptional.isPresent()) {
                TopologyManagerUtil.removeAffectedLinks(terminationPointId, manager, II_TO_TOPOLOGY);
                manager.addDeleteOperationToTxChain(LogicalDatastoreType.OPERATIONAL, iiToTopologyTerminationPoint);
            }
        });
    } else {
        LOG.debug("Instance identifier to inventory wasn't translated to topology while deleting termination point.");
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) TpId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint)

Aggregations

NodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector)20 FlowCapableNodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector)16 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)13 NodeConnectorKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)12 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)11 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)10 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)9 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)8 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)7 BigInteger (java.math.BigInteger)4 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)3 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)3 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Test (org.junit.Test)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 Tunnel (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel)2