Search in sources :

Example 21 with Link

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link in project bgpcep by opendaylight.

the class LinkstateTopologyBuilder method createLink.

private void createLink(final WriteTransaction trans, final UriBuilder base, final LinkstateRoute value, final LinkCase linkCase, final Attributes attributes) {
    // defensive lookup
    final LinkAttributes la;
    final Attributes1 attr = attributes.getAugmentation(Attributes1.class);
    if (attr != null) {
        final LinkStateAttribute attrType = attr.getLinkStateAttribute();
        if (attrType != null) {
            la = ((LinkAttributesCase) attrType).getLinkAttributes();
        } else {
            LOG.debug("Missing attribute type in link {} route {}, skipping it", linkCase, value);
            la = null;
        }
    } else {
        LOG.debug("Missing attributes in link {} route {}, skipping it", linkCase, value);
        la = null;
    }
    final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
    if (la != null) {
        if (la.getMetric() != null) {
            ilab.setMetric(la.getMetric().getValue());
        }
        ilab.setName(la.getLinkName());
    }
    ProtocolUtil.augmentProtocolId(value, ilab, la, linkCase.getLinkDescriptors());
    final LinkBuilder lb = new LinkBuilder();
    lb.setLinkId(buildLinkId(base, linkCase));
    lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
    final NodeId srcNode = buildNodeId(base, linkCase.getLocalNodeDescriptors());
    LOG.trace("Link {} implies source node {}", linkCase, srcNode);
    final NodeId dstNode = buildNodeId(base, linkCase.getRemoteNodeDescriptors());
    LOG.trace("Link {} implies destination node {}", linkCase, dstNode);
    final TerminationPoint srcTp = buildLocalTp(base, linkCase.getLinkDescriptors());
    LOG.trace("Link {} implies source TP {}", linkCase, srcTp);
    final TerminationPoint dstTp = buildRemoteTp(base, linkCase.getLinkDescriptors());
    LOG.trace("Link {} implies destination TP {}", linkCase, dstTp);
    lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
    lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
    LOG.trace("Created TP {} as link source", srcTp);
    NodeHolder snh = this.nodes.get(srcNode);
    if (snh == null) {
        snh = getNode(srcNode);
        snh.addTp(srcTp, lb.getLinkId(), false);
        putNode(trans, snh);
    } else {
        snh.addTp(srcTp, lb.getLinkId(), false);
        final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(snh.getNodeId()));
        trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp);
    }
    LOG.debug("Created TP {} as link destination", dstTp);
    NodeHolder dnh = this.nodes.get(dstNode);
    if (dnh == null) {
        dnh = getNode(dstNode);
        dnh.addTp(dstTp, lb.getLinkId(), true);
        putNode(trans, dnh);
    } else {
        dnh.addTp(dstTp, lb.getLinkId(), true);
        final InstanceIdentifier<Node> nid = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, new NodeKey(dnh.getNodeId()));
        trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);
    }
    final InstanceIdentifier<Link> lid = buildLinkIdentifier(lb.getLinkId());
    final Link link = lb.build();
    trans.put(LogicalDatastoreType.OPERATIONAL, lid, link);
    LOG.debug("Created link {} at {} for {}", link, lid, linkCase);
}
Also used : IgpLinkAttributesBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder) SourceBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder) LinkBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) Attributes1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.routes.linkstate.routes.linkstate.route.Attributes1) LinkStateAttribute(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.LinkStateAttribute) Link1Builder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder) LinkAttributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) DestinationBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)

Example 22 with Link

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link in project bgpcep by opendaylight.

the class LinkstateTopologyBuilder method removeLink.

private void removeLink(final WriteTransaction trans, final UriBuilder base, final LinkCase linkCase) {
    final LinkId id = buildLinkId(base, linkCase);
    final InstanceIdentifier<?> lid = buildLinkIdentifier(id);
    trans.delete(LogicalDatastoreType.OPERATIONAL, lid);
    LOG.debug("Removed link {}", lid);
    removeTp(trans, buildNodeId(base, linkCase.getLocalNodeDescriptors()), buildLocalTpId(base, linkCase.getLinkDescriptors()), id, false);
    removeTp(trans, buildNodeId(base, linkCase.getRemoteNodeDescriptors()), buildRemoteTpId(base, linkCase.getLinkDescriptors()), id, true);
}
Also used : LinkId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId)

Example 23 with Link

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link in project bgpcep by opendaylight.

the class LinkstateTopologyBuilder method removeTp.

private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp, final LinkId link, final boolean isRemote) {
    final NodeHolder nh = this.nodes.get(node);
    if (nh != null) {
        final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
        trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp)));
        nh.removeTp(tp, link, isRemote);
        checkNodeForRemoval(trans, nh);
    } else {
        LOG.warn("Removed non-existent node {}", node);
    }
}
Also used : TerminationPointKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NodeKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint)

Example 24 with Link

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link in project bgpcep by opendaylight.

the class LinkstateTopologyBuilderTest method testOspfLinkstateTopologyBuilder.

@Test
public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
    // create node
    updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
    readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
        assertEquals(1, topology.getNode().size());
        final Node node1 = topology.getNode().get(0);
        assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
        final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
        assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
        assertEquals("node1", igpNode1.getName().getValue());
        assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
        assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
        return topology;
    });
    // update node with prefix
    updateLinkstateRoute(createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX, 500L, ROUTER_1_ID));
    readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
        final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
        assertEquals(1, igpNode2.getPrefix().size());
        final Prefix prefix = igpNode2.getPrefix().get(0);
        assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
        assertEquals(500L, prefix.getMetric().longValue());
        return topology;
    });
    // create link
    updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.Ospf, NODE_1_AS, NODE_2_AS, "link1"));
    readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
        assertEquals(1, topology.getLink().size());
        final Link link1 = topology.getLink().get(0);
        assertEquals(2, topology.getNode().size());
        assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
        assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
        assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
        assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
        assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
        final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
        assertEquals("link1", igpLink1.getName());
        assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
        assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
        assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
        return topology;
    });
}
Also used : Collections(java.util.Collections) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) IgpNodeAttributes(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) Prefix(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) Node1(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1) IgpLinkAttributes1(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1) Link1(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1) IgpNodeAttributes1(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1) IgpLinkAttributes(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributes) Link(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link) Test(org.junit.Test)

Example 25 with Link

use of org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link in project bgpcep by opendaylight.

the class UriBuilder method add.

UriBuilder add(final LinkCase link) {
    addPrefix("local-", link.getLocalNodeDescriptors());
    addPrefix("remote-", link.getRemoteNodeDescriptors());
    final LinkDescriptors ld = link.getLinkDescriptors();
    if (ld.getIpv4InterfaceAddress() != null) {
        add("ipv4-iface", ld.getIpv4InterfaceAddress().getValue());
    }
    if (ld.getIpv4NeighborAddress() != null) {
        add("ipv4-neigh", ld.getIpv4NeighborAddress().getValue());
    }
    if (ld.getIpv6InterfaceAddress() != null) {
        add("ipv6-iface", ld.getIpv6InterfaceAddress().getValue());
    }
    if (ld.getIpv6NeighborAddress() != null) {
        add("ipv6-neigh", ld.getIpv6NeighborAddress().getValue());
    }
    if (ld.getMultiTopologyId() != null) {
        add("mt", ld.getMultiTopologyId().getValue());
    }
    add("local-id", ld.getLinkLocalIdentifier());
    add("remote-id", ld.getLinkRemoteIdentifier());
    return this;
}
Also used : LinkDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.LinkDescriptors)

Aggregations

Test (org.junit.Test)454 ByteBuf (io.netty.buffer.ByteBuf)138 ArrayList (java.util.ArrayList)71 BigInteger (java.math.BigInteger)58 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)54 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)51 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)45 VersionDatapathIdConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData)38 Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)37 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)35 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)35 InetAddress (java.net.InetAddress)33 SimpleAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress)33 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)32 MultipartReplyMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage)28 Inet4Address (java.net.Inet4Address)27 Inet6Address (java.net.Inet6Address)27 NoAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.NoAddress)27 LispAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.LispAddress)26 Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.Address)26