2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.bgpcep.bgp.topology.provider;
10 import java.math.BigDecimal;
11 import java.nio.ByteBuffer;
12 import java.util.ArrayList;
13 import java.util.List;
15 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
16 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
17 import org.opendaylight.protocol.bgp.rib.RibReference;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.DomainName;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeFlagBits;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.LinkstateRoute;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.Attributes1;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.ObjectType;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.link._case.LinkAttributes;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.node._case.NodeAttributes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.prefix._case.PrefixAttributes;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.LinkCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.NodeCase;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.PrefixCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.link._case.LinkDescriptors;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.object.type.node._case.NodeDescriptors;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.CRouterIdentifier;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisNodeCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.IsisPseudonodeCase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfNodeCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.OspfPseudonodeCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.node._case.OspfNode;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.ospf.pseudonode._case.OspfPseudonode;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
60 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
61 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
71 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
72 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
74 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
75 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
76 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1Builder;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
82 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
83 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix;
84 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixBuilder;
85 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.PrefixKey;
86 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
87 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.TerminationPointType;
88 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.IpBuilder;
89 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.igp.termination.point.attributes.termination.point.type.UnnumberedBuilder;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
91 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
93 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
94 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.AbrBuilder;
95 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.InternalBuilder;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.router.type.PseudonodeBuilder;
97 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
98 import org.opendaylight.yangtools.yang.binding.DataObject;
99 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
100 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
101 import org.slf4j.Logger;
102 import org.slf4j.LoggerFactory;
104 import com.google.common.collect.Lists;
105 import com.google.common.primitives.UnsignedInteger;
107 public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
108 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
110 public LinkstateTopologyBuilder(final DataProviderService dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
111 super(dataProvider, locRibReference, topologyId, new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class,
112 new TopologyTypes1Builder().build()).build(), LinkstateRoute.class);
115 private LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
116 return new LinkId(new UriBuilder(base, "link").add(link).toString());
119 private NodeId buildNodeId(final UriBuilder base, final NodeIdentifier node) {
120 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
123 private TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier,
124 final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final byte[] bs) {
125 return new TpId(new UriBuilder(base, "tp").add("mt", topologyIdentifier).add("ipv4", ipv4InterfaceIdentifier).add("ipv6",
126 ipv6InterfaceIdentifier).add("id", bs).toString());
129 private TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
130 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(),
131 linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
134 private TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
135 final TerminationPointBuilder stpb = new TerminationPointBuilder();
136 stpb.setKey(new TerminationPointKey(id));
140 stpb.addAugmentation(
141 TerminationPoint1.class,
142 new TerminationPoint1Builder().setIgpTerminationPointAttributes(
143 new IgpTerminationPointAttributesBuilder().setTerminationPointType(null).build()).build());
149 private TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier,
150 final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final byte[] bs) {
151 // Order of preference: Unnumbered first, then IP
153 final long id = UnsignedInteger.fromIntBits(ByteArray.bytesToInt(bs)).longValue();
154 LOG.debug("Unnumbered termination point type: {}", id);
155 return new UnnumberedBuilder().setUnnumberedId(id).build();
159 if (ipv6InterfaceIdentifier != null) {
160 ip = new IpAddress(ipv6InterfaceIdentifier);
161 } else if (ipv4InterfaceIdentifier != null) {
162 ip = new IpAddress(ipv4InterfaceIdentifier);
168 LOG.debug("IP termination point type: {}", ip);
169 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
175 private TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
176 final TpId id = buildLocalTpId(base, linkDescriptors);
177 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(),
178 linkDescriptors.getLinkLocalIdentifier());
180 return buildTp(id, t);
183 private TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
184 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(),
185 linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
188 private TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
189 final TpId id = buildRemoteTpId(base, linkDescriptors);
190 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(),
191 linkDescriptors.getLinkRemoteIdentifier());
193 return buildTp(id, t);
196 private InstanceIdentifier<?> buildLinkIdentifier(final UriBuilder base, final LinkCase l) {
197 return InstanceIdentifier.builder(getInstanceIdentifier()).child(
198 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
199 new LinkKey(buildLinkId(base, l))).toInstance();
202 private static Float bandwidthToFloat(final Bandwidth bandwidth) {
203 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
206 private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
207 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
210 private static List<UnreservedBandwidth> unreservedBandwidthList(
211 final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth> input) {
212 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
214 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth i : input) {
215 ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
216 new UnreservedBandwidthKey(i.getPriority())).build());
222 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
223 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
224 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.isis.link.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.isis.link.attributes.TedBuilder();
227 if (la.getAdminGroup() != null) {
228 tb.setColor(la.getAdminGroup().getValue());
230 if (la.getTeMetric() != null) {
231 tb.setTeDefaultMetric(la.getTeMetric().getValue());
233 if (la.getUnreservedBandwidth() != null) {
234 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
236 if (la.getMaxLinkBandwidth() != null) {
237 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
239 if (la.getMaxReservableBandwidth() != null) {
240 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
244 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
245 ilab.setTed(tb.build());
246 if (topologyIdentifier != null) {
247 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
250 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(
251 ilab.build()).build();
254 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
255 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
256 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.ospf.link.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.ospf.link.attributes.TedBuilder();
259 if (la.getAdminGroup() != null) {
260 tb.setColor(la.getAdminGroup().getValue());
262 if (la.getTeMetric() != null) {
263 tb.setTeDefaultMetric(la.getTeMetric().getValue());
265 if (la.getUnreservedBandwidth() != null) {
266 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
268 if (la.getMaxLinkBandwidth() != null) {
269 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
271 if (la.getMaxReservableBandwidth() != null) {
272 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
276 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
277 ilab.setTed(tb.build());
278 if (topologyIdentifier != null) {
279 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
282 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(
283 ilab.build()).build();
286 private void createLink(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
287 final LinkstateRoute value, final LinkCase l, final Attributes attributes) {
288 final LinkAttributes la = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.LinkCase) attributes.getAugmentation(
289 Attributes1.class).getAttributeType()).getLinkAttributes();
291 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
293 ilab.setMetric(la.getMetric().getValue());
294 ilab.setName(la.getLinkName());
297 switch (value.getProtocolId()) {
304 ilab.addAugmentation(
305 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
306 isisLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
309 ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
310 ospfLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
314 final LinkBuilder lb = new LinkBuilder();
315 lb.setLinkId(buildLinkId(base, l));
316 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
318 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
319 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
320 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
321 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
323 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
324 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
326 final InstanceIdentifier<TerminationPoint> stpId = buildTpIdentifier(srcNode, srcTp.getKey());
327 trans.putOperationalData(stpId, srcTp);
328 LOG.debug("Created TP {} at {} as link source", srcTp, stpId);
330 final InstanceIdentifier<TerminationPoint> dtpId = buildTpIdentifier(dstNode, dstTp.getKey());
331 trans.putOperationalData(dtpId, dstTp);
332 LOG.debug("Created TP {} at {} as link destination", dstTp, dtpId);
334 final InstanceIdentifier<?> lid = buildLinkIdentifier(base, l);
335 final Link link = lb.build();
336 trans.putOperationalData(lid, link);
337 LOG.debug("Created link {} at {} for {}", link, lid, l);
340 private void removeLink(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final LinkCase l) {
341 trans.removeOperationalData(buildLinkIdentifier(base, l));
344 private InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nodeIdentifierBuilder(
345 final UriBuilder base, final NodeIdentifier node) {
346 return InstanceIdentifier.builder(getInstanceIdentifier()).child(
347 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
348 new NodeKey(buildNodeId(base, node)));
351 private InstanceIdentifier<TerminationPoint> buildTpIdentifier(final NodeId node, final TerminationPointKey key) {
352 return InstanceIdentifier.builder(getInstanceIdentifier()).child(
353 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
354 new NodeKey(node)).child(TerminationPoint.class, key).build();
357 private List<Short> nodeMultiTopology(final List<TopologyIdentifier> list) {
358 final List<Short> ret = new ArrayList<>(list.size());
359 for (final TopologyIdentifier id : list) {
360 ret.add(id.getValue().shortValue());
365 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
366 final NodeIdentifier node, final NodeAttributes na) {
367 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.TedBuilder();
368 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
371 if (na.getIpv4RouterId() != null) {
372 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
374 if (na.getIpv6RouterId() != null) {
375 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
377 if (na.getTopologyIdentifier() != null) {
378 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
382 final CRouterIdentifier ri = node.getCRouterIdentifier();
383 if (ri instanceof IsisPseudonodeCase) {
384 final IsisPseudonode pn = ((IsisPseudonodeCase) ri).getIsisPseudonode();
385 ab.setIso(new IsoBuilder().setIsoPseudonodeId(new IsoPseudonodeId(pn.toString())).build());
386 } else if (ri instanceof IsisNodeCase) {
387 final IsisNode in = ((IsisNodeCase) ri).getIsisNode();
388 ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(in.getIsoSystemId().toString())).build());
391 ab.setTed(tb.build());
393 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
397 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
398 final NodeDescriptors node, final NodeAttributes na) {
399 final org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.TedBuilder tb = new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.ospf.node.attributes.TedBuilder();
400 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
403 if (na.getIpv4RouterId() != null) {
404 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
406 if (na.getIpv6RouterId() != null) {
407 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
409 if (na.getTopologyIdentifier() != null) {
410 ab.setMultiTopologyId(nodeMultiTopology(na.getTopologyIdentifier()));
414 final CRouterIdentifier ri = node.getCRouterIdentifier();
415 if (ri instanceof OspfPseudonodeCase) {
416 final OspfPseudonode pn = ((OspfPseudonodeCase) ri).getOspfPseudonode();
418 ab.setRouterType(new PseudonodeBuilder().setPseudonode(Boolean.TRUE).build());
419 ab.setDrInterfaceId(UnsignedInteger.fromIntBits(ByteArray.bytesToInt(pn.getLanInterface().getValue())).longValue());
420 } else if (ri instanceof OspfNodeCase) {
421 final OspfNode in = ((OspfNodeCase) ri).getOspfNode();
423 // TODO: what should we do with in.getOspfRouterId()?
426 final NodeFlagBits nf = na.getNodeFlags();
429 ab.setRouterType(new AbrBuilder().setAbr(Boolean.TRUE).build());
430 } else if (!nf.isExternal()) {
431 ab.setRouterType(new InternalBuilder().setInternal(Boolean.TRUE).build());
437 ab.setTed(tb.build());
439 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
443 private void createNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
444 final LinkstateRoute value, final NodeCase n, final Attributes attributes) {
445 final NodeAttributes na = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.NodeCase) attributes.getAugmentation(
446 Attributes1.class).getAttributeType()).getNodeAttributes();
447 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
449 final List<IpAddress> ids = new ArrayList<>();
451 if (na.getIpv4RouterId() != null) {
452 ids.add(new IpAddress(na.getIpv4RouterId()));
454 if (na.getIpv6RouterId() != null) {
455 ids.add(new IpAddress(na.getIpv6RouterId()));
457 if (na.getDynamicHostname() != null) {
458 inab.setName(new DomainName(na.getDynamicHostname()));
462 if (!ids.isEmpty()) {
463 inab.setRouterId(ids);
466 switch (value.getProtocolId()) {
473 inab.addAugmentation(
474 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
475 isisNodeAttributes(n.getNodeDescriptors(), na));
478 inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
479 ospfNodeAttributes(n.getNodeDescriptors(), na));
483 final NodeBuilder nb = new NodeBuilder();
484 nb.setNodeId(buildNodeId(base, n.getNodeDescriptors()));
485 nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(inab.build()).build());
487 final InstanceIdentifier<Node> nid = nodeIdentifierBuilder(base, n.getNodeDescriptors()).build();
488 final Node node = nb.build();
489 trans.putOperationalData(nid, node);
490 LOG.debug("Created node {} at {} for {}", node, nid, n);
493 private void removeNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final NodeCase n) {
494 trans.removeOperationalData(nodeIdentifierBuilder(base, n.getNodeDescriptors()).toInstance());
497 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix> prefixIdentifier(
498 final UriBuilder base, final PrefixCase p) {
499 return nodeIdentifierBuilder(base, p.getAdvertisingNodeDescriptors()).augmentation(Node1.class).child(
500 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes.class).child(
501 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix.class,
502 new PrefixKey(p.getIpReachabilityInformation())).toInstance();
505 private void createPrefix(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
506 final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
507 final PrefixAttributes pa = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.bgp.rib.rib.loc.rib.tables.routes.linkstate.routes._case.linkstate.routes.linkstate.route.attributes.attribute.type.PrefixCase) attributes.getAugmentation(
508 Attributes1.class).getAttributeType()).getPrefixAttributes();
510 final PrefixBuilder pb = new PrefixBuilder();
511 final IpPrefix ippfx = p.getIpReachabilityInformation();
512 pb.setKey(new PrefixKey(ippfx));
515 pb.setMetric(pa.getPrefixMetric().getValue());
518 switch (value.getProtocolId()) {
529 new Prefix1Builder().setOspfPrefixAttributes(
530 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress()).build()).build());
536 final Prefix pfx = pb.build();
537 final InstanceIdentifier<Prefix> pid = prefixIdentifier(base, p);
538 trans.putOperationalData(pid, pfx);
539 LOG.debug("Created prefix {} at {} for {}", pfx, pid, p);
542 private void removePrefix(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final PrefixCase p) {
543 trans.removeOperationalData(prefixIdentifier(base, p));
547 protected void createObject(final DataModification<InstanceIdentifier<?>, DataObject> trans,
548 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
549 final UriBuilder base = new UriBuilder(value);
551 final ObjectType t = value.getObjectType();
552 if (t instanceof LinkCase) {
553 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
554 } else if (t instanceof NodeCase) {
555 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
556 } else if (t instanceof PrefixCase) {
557 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
559 throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());
564 protected void removeObject(final DataModification<InstanceIdentifier<?>, DataObject> trans,
565 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
566 final UriBuilder base = new UriBuilder(value);
568 final ObjectType t = value.getObjectType();
569 if (t instanceof LinkCase) {
570 removeLink(trans, base, (LinkCase) t);
571 } else if (t instanceof NodeCase) {
572 removeNode(trans, base, (NodeCase) t);
573 } else if (t instanceof PrefixCase) {
574 removePrefix(trans, base, (PrefixCase) t);
576 throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());