Search in sources :

Example 71 with Node

use of Nodes.Node in project netvirt by opendaylight.

the class BaseVrfEntryHandler method makeConnectedRoute.

protected void makeConnectedRoute(BigInteger dpId, long vpnId, VrfEntry vrfEntry, String rd, List<InstructionInfo> instructions, int addOrRemove, WriteTransaction tx, List<SubTransaction> subTxns) {
    Boolean wrTxPresent = true;
    if (tx == null) {
        wrTxPresent = false;
        tx = dataBroker.newWriteOnlyTransaction();
    }
    LOG.trace("makeConnectedRoute: vrfEntry {}", vrfEntry);
    String[] values = vrfEntry.getDestPrefix().split("/");
    String ipAddress = values[0];
    int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
    if (addOrRemove == NwConstants.ADD_FLOW) {
        LOG.debug("Adding route to DPN {} for rd {} prefix {} ", dpId, rd, vrfEntry.getDestPrefix());
    } else {
        LOG.debug("Removing route from DPN {} for rd {} prefix {}", dpId, rd, vrfEntry.getDestPrefix());
    }
    InetAddress destPrefix;
    try {
        destPrefix = InetAddress.getByName(ipAddress);
    } catch (UnknownHostException e) {
        LOG.error("Failed to get destPrefix for prefix {} rd {} VpnId {} DPN {}", vrfEntry.getDestPrefix(), rd, vpnId, dpId, e);
        return;
    }
    List<MatchInfo> matches = new ArrayList<>();
    matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
    if (destPrefix instanceof Inet4Address) {
        matches.add(MatchEthernetType.IPV4);
        if (prefixLength != 0) {
            matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
        }
    } else {
        matches.add(MatchEthernetType.IPV6);
        if (prefixLength != 0) {
            matches.add(new MatchIpv6Destination(destPrefix.getHostAddress() + "/" + prefixLength));
        }
    }
    int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
    String flowRef = FibUtil.getFlowRef(dpId, NwConstants.L3_FIB_TABLE, rd, priority, destPrefix);
    FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
    Flow flow = flowEntity.getFlowBuilder().build();
    String flowId = flowEntity.getFlowId();
    FlowKey flowKey = new FlowKey(new FlowId(flowId));
    Node nodeDpn = FibUtil.buildDpnNode(dpId);
    InstanceIdentifier<Flow> flowInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
    if (RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.BGP) {
        SubTransaction subTransaction = new SubTransactionImpl();
        if (addOrRemove == NwConstants.ADD_FLOW) {
            subTransaction.setInstanceIdentifier(flowInstanceId);
            subTransaction.setInstance(flow);
            subTransaction.setAction(SubTransaction.CREATE);
        } else {
            subTransaction.setInstanceIdentifier(flowInstanceId);
            subTransaction.setAction(SubTransaction.DELETE);
        }
        subTxns.add(subTransaction);
    }
    if (addOrRemove == NwConstants.ADD_FLOW) {
        tx.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
    } else {
        tx.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId);
    }
    if (!wrTxPresent) {
        tx.submit();
    }
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) Inet4Address(java.net.Inet4Address) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) UnknownHostException(java.net.UnknownHostException) SubTransactionImpl(org.opendaylight.genius.utils.batching.SubTransactionImpl) 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) SubTransaction(org.opendaylight.genius.utils.batching.SubTransaction) MatchIpv4Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) MatchIpv6Destination(org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) InetAddress(java.net.InetAddress)

Example 72 with Node

use of Nodes.Node in project netvirt by opendaylight.

the class Ipv6RouterAdvt method transmitRtrAdvertisement.

public boolean transmitRtrAdvertisement(Ipv6RtrAdvertType raType, VirtualPort routerPort, List<NodeConnectorRef> outportList, RouterSolicitationPacket rsPdu) {
    RouterAdvertisementPacketBuilder raPacket = new RouterAdvertisementPacketBuilder();
    updateRAResponse(raType, rsPdu, raPacket, routerPort);
    // Serialize the response packet
    byte[] txPayload = fillRouterAdvertisementPacket(raPacket.build());
    for (NodeConnectorRef outport : outportList) {
        InstanceIdentifier<Node> outNode = outport.getValue().firstIdentifierOf(Node.class);
        TransmitPacketInput input = new TransmitPacketInputBuilder().setPayload(txPayload).setNode(new NodeRef(outNode)).setEgress(outport).build();
        LOG.debug("Transmitting the Router Advt packet out {}", outport);
        JdkFutures.addErrorLogging(packetService.transmitPacket(input), LOG, "transmitPacket");
    }
    return true;
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) RouterAdvertisementPacketBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.ipv6service.nd.packet.rev160620.RouterAdvertisementPacketBuilder)

Example 73 with Node

use of Nodes.Node in project openflowplugin by opendaylight.

the class OpenflowpluginTestServiceProvider method register.

public ObjectRegistration<OpenflowpluginTestServiceProvider> register(final ProviderContext ctx) {
    RoutedRpcRegistration<SalFlowService> addRoutedRpcImplementation = ctx.<SalFlowService>addRoutedRpcImplementation(SalFlowService.class, this);
    setFlowRegistration(addRoutedRpcImplementation);
    InstanceIdentifierBuilder<Nodes> builderII = InstanceIdentifier.<Nodes>builder(Nodes.class);
    NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
    NodeKey nodeKey = new NodeKey(nodeId);
    InstanceIdentifierBuilder<Node> nodeIdentifier = builderII.<Node, NodeKey>child(Node.class, nodeKey);
    InstanceIdentifier<Node> instance = nodeIdentifier.build();
    flowRegistration.registerPath(NodeContext.class, instance);
    RoutedRpcRegistration<SalFlowService> flowRegistration2 = getFlowRegistration();
    return new AbstractObjectRegistration<OpenflowpluginTestServiceProvider>(this) {

        @Override
        protected void removeRegistration() {
            flowRegistration2.close();
        }
    };
}
Also used : AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) SalFlowService(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)

Example 74 with Node

use of Nodes.Node 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 75 with Node

use of Nodes.Node in project openflowplugin by opendaylight.

the class ShellUtil method getAllNodes.

@Nonnull
public static List<OFNode> getAllNodes(final DataBroker broker) {
    List<Node> nodes = null;
    ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
    InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).build();
    try {
        CheckedFuture<Optional<Nodes>, ReadFailedException> checkedFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
        Optional<Nodes> result = checkedFuture.get();
        if (result.isPresent()) {
            nodes = result.get().getNode();
        }
    } catch (ExecutionException | InterruptedException | NullPointerException e) {
        LOG.error("Error reading nodes from Inventory DS", e);
    }
    if (nodes != null) {
        List<OFNode> nodeList = new ArrayList<>();
        for (Node node : nodes) {
            String[] nodeId = node.getId().getValue().split(":");
            String name = null;
            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 Collections.emptyList();
            }
            OFNode ofNode = new OFNode(Long.parseLong(nodeId[1]), name);
            LOG.trace("Added OFNode: {} to the list", ofNode.getNodeId());
            nodeList.add(ofNode);
        }
        Collections.sort(nodeList);
        return nodeList;
    }
    return Collections.emptyList();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) 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) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) ExecutionException(java.util.concurrent.ExecutionException) Nonnull(javax.annotation.Nonnull)

Aggregations

Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)112 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)58 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)56 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)54 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)43 Test (org.junit.Test)21 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)20 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)19 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)19 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)19 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)17 BigInteger (java.math.BigInteger)16 ArrayList (java.util.ArrayList)16 NodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder)16 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)15 Before (org.junit.Before)11 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)7 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)7 Optional (com.google.common.base.Optional)6