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.IpAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv4InterfaceIdentifier;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.Ipv6InterfaceIdentifier;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.NodeIdentifier;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.TopologyIdentifier;
24 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;
25 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;
26 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;
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.linkstate.route.attributes.attribute.type.link._case.LinkAttributes;
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.attributes.attribute.type.node._case.NodeAttributes;
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.attributes.attribute.type.prefix._case.PrefixAttributes;
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.object.type.LinkCase;
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.object.type.NodeCase;
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.object.type.PrefixCase;
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.link._case.LinkDescriptors;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.CRouterIdentifier;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.node._case.IsisNode;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonode;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
39 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoPseudonodeId;
40 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IsoSystemId;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.link.attributes.IsisLinkAttributesBuilder;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.IsisNodeAttributesBuilder;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.isis.node.attributes.isis.node.attributes.IsoBuilder;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidth;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthBuilder;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.ted.rev131021.ted.link.attributes.UnreservedBandwidthKey;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypesBuilder;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
60 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
61 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1Builder;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1Builder;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1;
66 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TerminationPoint1Builder;
67 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1;
68 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.TopologyTypes1Builder;
69 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.link.attributes.IgpLinkAttributesBuilder;
70 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributesBuilder;
71 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;
72 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;
73 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.termination.point.attributes.IgpTerminationPointAttributesBuilder;
74 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;
75 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;
76 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;
77 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1;
78 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.Prefix1Builder;
79 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.link.attributes.OspfLinkAttributesBuilder;
80 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.node.attributes.OspfNodeAttributesBuilder;
81 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.ospf.prefix.attributes.OspfPrefixAttributesBuilder;
82 import org.opendaylight.yangtools.yang.binding.DataObject;
83 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
84 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
85 import org.slf4j.Logger;
86 import org.slf4j.LoggerFactory;
88 import com.google.common.collect.Lists;
89 import com.google.common.primitives.UnsignedInteger;
91 public final class LinkstateTopologyBuilder extends AbstractTopologyBuilder<LinkstateRoute> {
92 private static final Logger LOG = LoggerFactory.getLogger(LinkstateTopologyBuilder.class);
94 public LinkstateTopologyBuilder(final DataProviderService dataProvider, final RibReference locRibReference, final TopologyId topologyId) {
95 super(dataProvider, locRibReference, topologyId,
96 new TopologyTypesBuilder().addAugmentation(TopologyTypes1.class, new TopologyTypes1Builder().build()).build(), LinkstateRoute.class);
99 private LinkId buildLinkId(final UriBuilder base, final LinkCase link) {
100 return new LinkId(new UriBuilder(base, "link").add(link).toString());
103 private NodeId buildNodeId(final UriBuilder base, final NodeIdentifier node) {
104 return new NodeId(new UriBuilder(base, "node").add("", node).toString());
107 private TpId buildTpId(final UriBuilder base, final TopologyIdentifier topologyIdentifier, final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final byte[] bs) {
108 return new TpId(new UriBuilder(base, "tp").add("mt", topologyIdentifier).add("ipv4", ipv4InterfaceIdentifier).add("ipv6", ipv6InterfaceIdentifier).add("id", bs).toString());
111 private TpId buildLocalTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
112 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
115 private TerminationPoint buildTp(final TpId id, final TerminationPointType type) {
116 final TerminationPointBuilder stpb = new TerminationPointBuilder();
117 stpb.setKey(new TerminationPointKey(id));
121 stpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes(new IgpTerminationPointAttributesBuilder().setTerminationPointType(null).build()).build());
127 private final TerminationPointType getTpType(final Ipv4InterfaceIdentifier ipv4InterfaceIdentifier, final Ipv6InterfaceIdentifier ipv6InterfaceIdentifier, final byte[] bs) {
128 // Order of preference: Unnumbered first, then IP
130 final long id = UnsignedInteger.fromIntBits(ByteArray.bytesToInt(bs)).longValue();
131 LOG.debug("Unnumbered termination point type: {}", id);
132 return new UnnumberedBuilder().setUnnumberedId(id).build();
136 if (ipv6InterfaceIdentifier != null) {
137 ip = new IpAddress(ipv6InterfaceIdentifier);
138 } else if (ipv4InterfaceIdentifier != null) {
139 ip = new IpAddress(ipv4InterfaceIdentifier);
145 LOG.debug("IP termination point type: {}", ip);
146 return new IpBuilder().setIpAddress(Lists.newArrayList(ip)).build();
152 private TerminationPoint buildLocalTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
153 final TpId id = buildLocalTpId(base, linkDescriptors);
154 final TerminationPointType t = getTpType(linkDescriptors.getIpv4InterfaceAddress(), linkDescriptors.getIpv6InterfaceAddress(), linkDescriptors.getLinkLocalIdentifier());
156 return buildTp(id, t);
159 private TpId buildRemoteTpId(final UriBuilder base, final LinkDescriptors linkDescriptors) {
160 return buildTpId(base, linkDescriptors.getMultiTopologyId(), linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
163 private TerminationPoint buildRemoteTp(final UriBuilder base, final LinkDescriptors linkDescriptors) {
164 final TpId id = buildRemoteTpId(base, linkDescriptors);
165 final TerminationPointType t = getTpType(linkDescriptors.getIpv4NeighborAddress(), linkDescriptors.getIpv6NeighborAddress(), linkDescriptors.getLinkRemoteIdentifier());
167 return buildTp(id, t);
170 private InstanceIdentifier<?> buildLinkIdentifier(final UriBuilder base, final LinkCase l) {
171 return InstanceIdentifier.builder(getInstanceIdentifier()).child(
172 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link.class,
173 new LinkKey(buildLinkId(base, l))).toInstance();
176 private static Float bandwidthToFloat(final Bandwidth bandwidth) {
177 return ByteBuffer.wrap(bandwidth.getValue()).getFloat();
180 private static BigDecimal bandwidthToBigDecimal(final Bandwidth bandwidth) {
181 return BigDecimal.valueOf(bandwidthToFloat(bandwidth));
184 private static List<UnreservedBandwidth> unreservedBandwidthList(
185 final List<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth> input) {
186 final List<UnreservedBandwidth> ret = new ArrayList<>(input.size());
188 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.UnreservedBandwidth i : input) {
189 ret.add(new UnreservedBandwidthBuilder().setBandwidth(bandwidthToBigDecimal(i.getBandwidth())).setKey(
190 new UnreservedBandwidthKey(i.getPriority())).build());
196 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1 isisLinkAttributes(
197 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
198 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();
200 if (la.getAdminGroup() != null) {
201 tb.setColor(la.getAdminGroup().getValue());
203 if (la.getTeMetric() != null) {
204 tb.setTeDefaultMetric(la.getTeMetric().getValue());
206 if (la.getUnreservedBandwidth() != null) {
207 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
209 if (la.getMaxLinkBandwidth() != null) {
210 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
212 if (la.getMaxReservableBandwidth() != null) {
213 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
216 final IsisLinkAttributesBuilder ilab = new IsisLinkAttributesBuilder();
217 ilab.setTed(tb.build());
218 if (topologyIdentifier != null) {
219 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
222 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1Builder().setIsisLinkAttributes(ilab.build()).build();
225 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1 ospfLinkAttributes(
226 final TopologyIdentifier topologyIdentifier, final LinkAttributes la) {
227 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();
229 if (la.getAdminGroup() != null) {
230 tb.setColor(la.getAdminGroup().getValue());
232 if (la.getTeMetric() != null) {
233 tb.setTeDefaultMetric(la.getTeMetric().getValue());
235 if (la.getUnreservedBandwidth() != null) {
236 tb.setUnreservedBandwidth(unreservedBandwidthList(la.getUnreservedBandwidth()));
238 if (la.getMaxLinkBandwidth() != null) {
239 tb.setMaxLinkBandwidth(bandwidthToBigDecimal(la.getMaxLinkBandwidth()));
241 if (la.getMaxReservableBandwidth() != null) {
242 tb.setMaxResvLinkBandwidth(bandwidthToBigDecimal(la.getMaxReservableBandwidth()));
245 final OspfLinkAttributesBuilder ilab = new OspfLinkAttributesBuilder();
246 ilab.setTed(tb.build());
247 if (topologyIdentifier != null) {
248 ilab.setMultiTopologyId(topologyIdentifier.getValue().shortValue());
251 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1Builder().setOspfLinkAttributes(ilab.build()).build();
254 private void createLink(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final LinkstateRoute value,
255 final LinkCase l, final Attributes attributes) {
256 final LinkAttributes la =
257 ((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(Attributes1.class).getAttributeType()).getLinkAttributes();
259 final IgpLinkAttributesBuilder ilab = new IgpLinkAttributesBuilder();
260 ilab.setMetric(la.getMetric().getValue());
261 ilab.setName(la.getLinkName());
263 switch (value.getProtocolId()) {
270 ilab.addAugmentation(
271 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1.class,
272 isisLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
275 ilab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class,
276 ospfLinkAttributes(l.getLinkDescriptors().getMultiTopologyId(), la));
280 final LinkBuilder lb = new LinkBuilder();
281 lb.setLinkId(buildLinkId(base, l));
282 lb.addAugmentation(Link1.class, new Link1Builder().setIgpLinkAttributes(ilab.build()).build());
284 final NodeId srcNode = buildNodeId(base, l.getLocalNodeDescriptors());
285 final NodeId dstNode = buildNodeId(base, l.getRemoteNodeDescriptors());
286 final TerminationPoint srcTp = buildLocalTp(base, l.getLinkDescriptors());
287 final TerminationPoint dstTp = buildRemoteTp(base, l.getLinkDescriptors());
289 lb.setSource(new SourceBuilder().setSourceNode(srcNode).setSourceTp(srcTp.getTpId()).build());
290 lb.setDestination(new DestinationBuilder().setDestNode(dstNode).setDestTp(dstTp.getTpId()).build());
292 trans.putOperationalData(buildTpIdentifier(srcNode, srcTp.getKey()), srcTp);
293 trans.putOperationalData(buildTpIdentifier(dstNode, dstTp.getKey()), dstTp);
294 trans.putOperationalData(buildLinkIdentifier(base, l), lb.build());
295 LOG.debug("Created link {}", l);
298 private void removeLink(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final LinkCase l) {
299 trans.removeOperationalData(buildLinkIdentifier(base, l));
302 private InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> nodeIdentifierBuilder(
303 final UriBuilder base, final NodeIdentifier node) {
304 return InstanceIdentifier.builder(getInstanceIdentifier()).child(
305 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
306 new NodeKey(buildNodeId(base, node)));
309 private InstanceIdentifier<TerminationPoint> buildTpIdentifier(final NodeId node, final TerminationPointKey key) {
310 return InstanceIdentifier.builder(getInstanceIdentifier()).child(
311 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
312 new NodeKey(node)).child(TerminationPoint.class, key).build();
315 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1 isisNodeAttributes(
316 final NodeIdentifier node, final NodeAttributes na) {
317 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();
318 if (na.getIpv4RouterId() != null) {
319 tb.setTeRouterIdIpv4(na.getIpv4RouterId());
321 if (na.getIpv6RouterId() != null) {
322 tb.setTeRouterIdIpv6(na.getIpv6RouterId());
325 final IsisNodeAttributesBuilder ab = new IsisNodeAttributesBuilder();
326 final CRouterIdentifier ri = node.getCRouterIdentifier();
328 if (ri instanceof IsisPseudonode) {
329 final IsisPseudonode pn = (IsisPseudonode) ri;
330 ab.setIso(new IsoBuilder().setIsoPseudonodeId(new IsoPseudonodeId(pn.toString())).build());
331 } else if (ri instanceof IsisNode) {
332 final IsisNode in = (IsisNode) ri;
333 ab.setIso(new IsoBuilder().setIsoSystemId(new IsoSystemId(in.getIsoSystemId().toString())).build());
336 ab.setTed(tb.build());
338 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1Builder().setIsisNodeAttributes(
342 private org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1 ospfNodeAttributes(
343 final NodeAttributes na) {
344 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();
346 final OspfNodeAttributesBuilder ab = new OspfNodeAttributesBuilder();
348 ab.setTed(tb.build());
350 return new org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1Builder().setOspfNodeAttributes(
354 private void createNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final LinkstateRoute value,
355 final NodeCase n, final Attributes attributes) {
356 final NodeAttributes na =
357 ((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(Attributes1.class).getAttributeType()).getNodeAttributes();
359 final List<IpAddress> ids = new ArrayList<>();
360 if (na.getIpv4RouterId() != null) {
361 ids.add(new IpAddress(na.getIpv4RouterId()));
363 if (na.getIpv6RouterId() != null) {
364 ids.add(new IpAddress(na.getIpv6RouterId()));
367 final IgpNodeAttributesBuilder inab = new IgpNodeAttributesBuilder();
368 if (!ids.isEmpty()) {
369 inab.setRouterId(ids);
372 switch (value.getProtocolId()) {
379 inab.addAugmentation(
380 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1.class,
381 isisNodeAttributes(n.getNodeDescriptors(), na));
384 inab.addAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class,
385 ospfNodeAttributes(na));
389 final NodeBuilder nb = new NodeBuilder();
390 nb.setNodeId(buildNodeId(base, n.getNodeDescriptors()));
391 nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(inab.build()).build());
393 trans.putOperationalData(nodeIdentifierBuilder(base, n.getNodeDescriptors()).toInstance(), nb.build());
394 LOG.debug("Created node {}", n);
397 private void removeNode(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final NodeCase n) {
398 trans.removeOperationalData(nodeIdentifierBuilder(base, n.getNodeDescriptors()).toInstance());
401 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(
402 final UriBuilder base, final PrefixCase p) {
403 return nodeIdentifierBuilder(base, p.getAdvertisingNodeDescriptors()).augmentation(Node1.class).child(
404 org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes.class).child(
405 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,
406 new PrefixKey(p.getIpReachabilityInformation())).toInstance();
409 private void createPrefix(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base,
410 final LinkstateRoute value, final PrefixCase p, final Attributes attributes) {
411 final PrefixAttributes pa =
412 ((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(Attributes1.class).getAttributeType()).getPrefixAttributes();
414 final PrefixBuilder pb = new PrefixBuilder();
415 pb.setPrefix(p.getIpReachabilityInformation());
416 pb.setMetric(pa.getPrefixMetric().getValue());
418 switch (value.getProtocolId()) {
428 new Prefix1Builder().setOspfPrefixAttributes(
429 new OspfPrefixAttributesBuilder().setForwardingAddress(pa.getOspfForwardingAddress()).build()).build());
433 trans.putOperationalData(prefixIdentifier(base, p), pb.build());
434 LOG.debug("Created prefix {}", p);
437 private void removePrefix(final DataModification<InstanceIdentifier<?>, DataObject> trans, final UriBuilder base, final PrefixCase p) {
438 trans.removeOperationalData(prefixIdentifier(base, p));
442 protected void createObject(final DataModification<InstanceIdentifier<?>, DataObject> trans,
443 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
444 final UriBuilder base = new UriBuilder(value);
446 final ObjectType t = value.getObjectType();
447 if (t instanceof LinkCase) {
448 createLink(trans, base, value, (LinkCase) t, value.getAttributes());
449 } else if (t instanceof NodeCase) {
450 createNode(trans, base, value, (NodeCase) t, value.getAttributes());
451 } else if (t instanceof PrefixCase) {
452 createPrefix(trans, base, value, (PrefixCase) t, value.getAttributes());
454 throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());
459 protected void removeObject(final DataModification<InstanceIdentifier<?>, DataObject> trans,
460 final InstanceIdentifier<LinkstateRoute> id, final LinkstateRoute value) {
461 final UriBuilder base = new UriBuilder(value);
463 final ObjectType t = value.getObjectType();
464 if (t instanceof LinkCase) {
465 removeLink(trans, base, (LinkCase) t);
466 } else if (t instanceof NodeCase) {
467 removeNode(trans, base, (NodeCase) t);
468 } else if (t instanceof PrefixCase) {
469 removePrefix(trans, base, (PrefixCase) t);
471 throw new IllegalStateException("Unhandled object class " + t.getImplementedInterface());