BUG-2982 : moved path-attributes container to grouping
[bgpcep.git] / bgp / linkstate / src / main / java / org / opendaylight / protocol / bgp / linkstate / nlri / LinkNlriParser.java
index 32a2a6a2337282dcc8695624bafa2a709e2d94f1..967ffbdc02d0efa9eec53312b5b1012184b7a630 100644 (file)
@@ -15,11 +15,16 @@ import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv6InterfaceIdentifier;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.TopologyIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.c.linkstate.destination.LinkDescriptors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.c.linkstate.destination.LinkDescriptorsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,6 +43,14 @@ public final class LinkNlriParser {
     private static final int IPV6_IFACE_ADDRESS = 261;
     private static final int IPV6_NEIGHBOR_ADDRESS = 262;
 
+    /* Link Descriptor QNames */
+    private static final NodeIdentifier IPV4_IFACE_NID = new NodeIdentifier(QName.cachedReference(QName.create(LinkDescriptors.QNAME, "ipv4-interface-address")));
+    private static final NodeIdentifier IPV6_IFACE_NID = new NodeIdentifier(QName.cachedReference(QName.create(LinkDescriptors.QNAME, "ipv6-interface-address")));
+    private static final NodeIdentifier IPV4_NEIGHBOR_NID = new NodeIdentifier(QName.cachedReference(QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address")));
+    private static final NodeIdentifier IPV6_NEIGHBOR_NID = new NodeIdentifier(QName.cachedReference(QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address")));
+    private static final NodeIdentifier LINK_LOCAL_NID = new NodeIdentifier(QName.cachedReference(QName.create(LinkDescriptors.QNAME, "link-local-identifier")));
+    private static final NodeIdentifier LINK_REMOTE_NID = new NodeIdentifier(QName.cachedReference(QName.create(LinkDescriptors.QNAME, "link-remote-identifier")));
+
     static LinkDescriptors parseLinkDescriptors(final ByteBuf buffer) throws BGPParsingException {
         final LinkDescriptorsBuilder builder = new LinkDescriptorsBuilder();
         while (buffer.isReadable()) {
@@ -108,4 +121,28 @@ public final class LinkNlriParser {
             TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, Unpooled.copyShort(descriptors.getMultiTopologyId().getValue()), buffer);
         }
     }
+
+    static void serializeLinkDescriptors(final ContainerNode descriptors, final ByteBuf buffer) {
+        if (descriptors.getChild(LINK_LOCAL_NID).isPresent() && descriptors.getChild(LINK_REMOTE_NID).isPresent()) {
+            final ByteBuf identifierBuf = Unpooled.buffer();
+            identifierBuf.writeInt(((Long)descriptors.getChild(LINK_LOCAL_NID).get().getValue()).intValue());
+            identifierBuf.writeInt(((Long)descriptors.getChild(LINK_REMOTE_NID).get().getValue()).intValue());
+            TlvUtil.writeTLV(LINK_LR_IDENTIFIERS, identifierBuf, buffer);
+        }
+        if (descriptors.getChild(IPV4_IFACE_NID).isPresent()) {
+            TlvUtil.writeTLV(IPV4_IFACE_ADDRESS, Ipv4Util.byteBufForAddress(new Ipv4Address((String)descriptors.getChild(IPV4_IFACE_NID).get().getValue())), buffer);
+        }
+        if (descriptors.getChild(IPV6_IFACE_NID).isPresent()) {
+            TlvUtil.writeTLV(IPV6_IFACE_ADDRESS, Ipv6Util.byteBufForAddress(new Ipv6Address((String)descriptors.getChild(IPV6_IFACE_NID).get().getValue())), buffer);
+        }
+        if (descriptors.getChild(IPV4_NEIGHBOR_NID).isPresent()) {
+            TlvUtil.writeTLV(IPV4_NEIGHBOR_ADDRESS, Ipv4Util.byteBufForAddress(new Ipv4Address((String)descriptors.getChild(IPV4_NEIGHBOR_NID).get().getValue())), buffer);
+        }
+        if (descriptors.getChild(IPV6_NEIGHBOR_NID).isPresent()) {
+            TlvUtil.writeTLV(IPV6_NEIGHBOR_ADDRESS, Ipv6Util.byteBufForAddress(new Ipv6Address((String)descriptors.getChild(IPV6_NEIGHBOR_NID).get().getValue())), buffer);
+        }
+        if (descriptors.getChild(TlvUtil.MULTI_TOPOLOGY_NID).isPresent()) {
+            TlvUtil.writeTLV(TlvUtil.MULTI_TOPOLOGY_ID, Unpooled.copyShort((Short)descriptors.getChild(TlvUtil.MULTI_TOPOLOGY_NID).get().getValue()), buffer);
+        }
+    }
 }