Update BMP to conform RFC 7854 93/40293/3
authorMilos Fabian <milfabia@cisco.com>
Tue, 14 Jun 2016 10:27:18 +0000 (12:27 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 16 Jun 2016 15:57:13 +0000 (15:57 +0000)
*Added new Peer-Type - "Local Instance Peer"
*Deprecate current distinguisher representation
and replace it with bgp project wide definition of RD
*Update references in Yang Data Model

Change-Id: I5deef00e942b12ce1e8b3504d6de278aa1f70c41
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/bmp-api/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bmp/message/rev150512/PeerPeerDistinguisherBuilder.java [new file with mode: 0644]
bgp/bmp-api/src/main/yang/bmp-message.yang
bgp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpPerPeerMessageParser.java
bgp/bmp-spi/src/main/java/org/opendaylight/protocol/bmp/spi/parser/PeerDistinguisherUtil.java
bgp/bmp-spi/src/test/java/org/opendaylight/protocol/bmp/spi/parser/AbstractBmpPerPeerMessageParserTest.java

diff --git a/bgp/bmp-api/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bmp/message/rev150512/PeerPeerDistinguisherBuilder.java b/bgp/bmp-api/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/bmp/message/rev150512/PeerPeerDistinguisherBuilder.java
new file mode 100644 (file)
index 0000000..99d8396
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisherBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.Peer.PeerDistinguisher;
+
+
+/**
+ * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
+ * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
+ *
+ * The reason behind putting it under src/main/java is:
+ * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
+ * loss of user code.
+ *
+ */
+public final class PeerPeerDistinguisherBuilder {
+
+    public static PeerDistinguisher getDefaultInstance(final String defaultValue) {
+        try {
+            final RouteDistinguisher rd = RouteDistinguisherBuilder.getDefaultInstance(defaultValue);
+            return new PeerDistinguisher(rd);
+        } catch (final IllegalArgumentException e) {
+            return new PeerDistinguisher(defaultValue.getBytes());
+        }
+    }
+
+}
index 0e054ee6e3e2aeeeba4371bae99d3fcee7bc0191..bda664b5a12e860d6a6acde6d1601dfbc35dae9e 100644 (file)
@@ -7,13 +7,14 @@ module bmp-message {
     import bgp-multiprotocol { prefix bgp-mp; revision-date 2013-09-19; }
     import ietf-inet-types { prefix inet; revision-date 2010-09-24; }
     import ietf-yang-types { prefix yang; revision-date 2010-09-24; }
+    import bgp-types { prefix bgp-t; revision-date 2013-09-19; }
 
     organization "Cisco Systems, Inc.";
     contact "Milos Fabian <milfabia@cisco.com>";
 
     description
         "This module contains the base data model of a BMP messages.
-        It rolls up the definitions contained in draft-ietf-grow-bmp-07.
+        It rolls up the definitions contained in RFC7854.
 
         Copyright (c)2015 Cisco Systems, Inc. All rights reserved.
 
@@ -23,7 +24,7 @@ module bmp-message {
         http://www.eclipse.org/legal/epl-v10.html";
 
    reference
-        "https://tools.ietf.org/html/draft-ietf-grow-bmp-07";
+        "https://tools.ietf.org/html/rfc7854";
 
     revision "2015-05-12" {
         description
@@ -54,6 +55,14 @@ module bmp-message {
                     "Redundant connection. The router has determined
                      that this connection is redundant with another one.";
             }
+            enum permanently-closed {
+                value 4;
+                description
+                    "Session permanently administratively closed,
+                     will not be re-initiated.  Monitoring station should reduce
+                     (potentially to 0) the rate at which it attempts
+                     reconnection to the monitored router.";
+            }
         }
     }
 
@@ -81,7 +90,11 @@ module bmp-message {
             }
             enum l3vpn {
                 value 1;
-                description "L3 VPN Instance Peer.";
+                description "RD Instance Peer.";
+            }
+            enum local {
+                value 2;
+                description "Local Instance Peer";
             }
         }
     }
@@ -98,6 +111,7 @@ module bmp-message {
                 value 2;
             }
         }
+        status deprecated;
     }
 
     typedef mirror-information-code {
@@ -387,6 +401,18 @@ module bmp-message {
                  If the peer is a L3VPN Instance Peer, it is set to the
                  route distinguisher of the particular L3VPN instance that the peer
                  belongs to.";
+            status deprecated;
+        }
+        leaf peer-distinguisher {
+            type union {
+                type bgp-t:route-distinguisher;
+                type binary {
+                    length 8;
+                }
+            }
+            description
+                "This field is present to distinguish peers that
+                 belong to one address domain from the other.";
         }
         leaf address {
             type inet:ip-address;
@@ -436,7 +462,7 @@ module bmp-message {
               The rest of the data in a BMP message is dependent on the Message
               Type field in the common header.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.2";
+            "https://tools.ietf.org/html/rfc7854#section-4.2";
     }
 
     grouping stat {
@@ -537,7 +563,7 @@ module bmp-message {
             "The initiation message provides a means for the monitored router to
              inform the monitoring station of its vendor, software version, and so on.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.3";
+            "https://tools.ietf.org/html/rfc7854#section-4.3";
     }
 
     notification termination-message {
@@ -546,7 +572,7 @@ module bmp-message {
             "The termination message provides a way for a monitored router to
              indicate why it is terminating a session.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.4";
+            "https://tools.ietf.org/html/rfc7854#section-4.5";
     }
 
     notification route-monitoring-message {
@@ -559,7 +585,7 @@ module bmp-message {
              ADJ-RIBs-In.  They are also used for ongoing monitoring of received
              advertisements and withdraws.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.5";
+            "https://tools.ietf.org/html/rfc7854#section-4.6";
     }
 
     notification route-mirroring-message {
@@ -569,7 +595,7 @@ module bmp-message {
             "Route Mirroring messages are used for verbatim duplication of
              messages as received.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-15#section-4.7";
+            "https://tools.ietf.org/html/rfc7854#section-4.7";
     }
 
     notification stats-reports-message {
@@ -580,7 +606,7 @@ module bmp-message {
              monitoring station to observe interesting events that occur on the
              router.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.6";
+            "https://tools.ietf.org/html/rfc7854#section-4.8";
     }
 
     notification peer-down-notification {
@@ -590,7 +616,7 @@ module bmp-message {
             "This message is used to indicate that a peering session was
              terminated.";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.7";
+            "https://tools.ietf.org/html/rfc7854#section-4.9";
     }
 
     notification peer-up-notification {
@@ -600,6 +626,6 @@ module bmp-message {
             "The Peer Up message is used to indicate that a peering session has
              come up (i.e., has transitioned into ESTABLISHED state).";
         reference
-            "https://tools.ietf.org/html/draft-ietf-grow-bmp-07#section-4.8";
+            "https://tools.ietf.org/html/rfc7854#section-4.10";
     }
 }
index cae1de44aebb327a58f6ba839384d7880cce2f86..0a2a7e2573123d67a16960bdccf6198413faa583 100644 (file)
@@ -10,8 +10,10 @@ package org.opendaylight.protocol.bmp.spi.parser;
 
 import com.google.common.base.Preconditions;
 import io.netty.buffer.ByteBuf;
+import org.opendaylight.bgp.concepts.RouteDistinguisherUtil;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.util.BitArray;
+import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.ByteBufWriteUtil;
 import org.opendaylight.protocol.util.Ipv4Util;
 import org.opendaylight.protocol.util.Ipv6Util;
@@ -19,6 +21,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Timestamp;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.AdjRibInType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.Peer.PeerDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.peer.header.PeerHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.peer.header.PeerHeaderBuilder;
@@ -56,14 +59,23 @@ public abstract class AbstractBmpPerPeerMessageParser<T  extends Builder<?>> ext
     protected final PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
         Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
         final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
-        phBuilder.setType(PeerType.forValue(bytes.readByte()));
+        final PeerType peerType = PeerType.forValue(bytes.readByte());
+        phBuilder.setType(peerType);
         final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
         phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
         phBuilder.setIpv4(!flags.get(V_FLAG_POS));
-        if (phBuilder.getType().equals(PeerType.L3vpn)) {
-            phBuilder.setDistinguisher(PeerDistinguisherUtil.parsePeerDistingisher(bytes));
-        } else {
+        switch (peerType) {
+        case L3vpn:
+            phBuilder.setDistinguisher(PeerDistinguisherUtil.parsePeerDistingisher(bytes.slice()));
+            phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
+            break;
+        case Local:
+            phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
+            break;
+        case Global:
+        default:
             bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
+            break;
         }
         if (phBuilder.isIpv4()) {
             bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
@@ -80,15 +92,28 @@ public abstract class AbstractBmpPerPeerMessageParser<T  extends Builder<?>> ext
 
     protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
         Preconditions.checkArgument(peerHeader != null, "Per-peer header cannot be null.");
-        output.writeByte(peerHeader.getType().getIntValue());
+        final PeerType peerType = peerHeader.getType();
+        output.writeByte(peerType.getIntValue());
         final BitArray flags = new BitArray(FLAGS_SIZE);
         flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() == 0 ? false : true);
         flags.set(V_FLAG_POS, !peerHeader.isIpv4());
         flags.toByteBuf(output);
-        if (peerHeader.getType().equals(PeerType.L3vpn)) {
-            PeerDistinguisherUtil.serializePeerDistinguisher(peerHeader.getDistinguisher(), output);
-        } else {
+        final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher();
+        switch (peerType) {
+        case L3vpn:
+            if (peerDistinguisher.getRouteDistinguisher() != null) {
+                RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
+            } else {
+                PeerDistinguisherUtil.serializePeerDistinguisher(peerHeader.getDistinguisher(), output);
+            }
+            break;
+        case Local:
+            output.writeBytes(peerDistinguisher.getBinary());
+            break;
+        case Global:
+        default:
             output.writeZero(PEER_DISTINGUISHER_SIZE);
+            break;
         }
         if (peerHeader.isIpv4()) {
             output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
index 23abb9349306f478e296af039b4198b96cea2317..e9a3075607f027b0db514f2510536c7005c8fc3d 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.mess
  * @see <a href="https://tools.ietf.org/html/rfc4364#section-4.2">https://tools.ietf.org/html/rfc4364#section-4.2</a>
  *
  */
+@Deprecated
 public final class PeerDistinguisherUtil {
 
     private static final class PeerDistinguisher {
index 1eeb81db93f1fc47a640b07572ca2936012e5f1d..78a6c1e1dcd9da04eb4505965c4d578e16b9ddbb 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.protocol.bmp.spi.parser;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import org.junit.Before;
@@ -23,8 +24,11 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Timestamp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RdTwoOctetAs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.RouteDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.AdjRibInType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.DistinguisherType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.Peer.PeerDistinguisher;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerUpNotification;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.PeerUpNotificationBuilder;
@@ -39,6 +43,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
  * Created by cgasparini on 18.5.2015.
  */
 public class AbstractBmpPerPeerMessageParserTest {
+    private static final String RD = "5:3";
     protected BGPExtensionProviderContext ctx;
     private AbstractBmpPerPeerMessageParser<?> parser;
     final byte[] ipv6MsgWithDistinguishergBytes = {
@@ -105,8 +110,9 @@ public class AbstractBmpPerPeerMessageParserTest {
 
         final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
         phBuilder.setType(PeerType.L3vpn);
-        final Distinguisher dist = new DistinguisherBuilder().setDistinguisher("5:3").setDistinguisherType(DistinguisherType.Type0).build();
+        final Distinguisher dist = new DistinguisherBuilder().setDistinguisher(RD).setDistinguisherType(DistinguisherType.Type0).build();
         phBuilder.setDistinguisher(dist);
+        phBuilder.setPeerDistinguisher(new PeerDistinguisher(new RouteDistinguisher(new RdTwoOctetAs("0:" + RD))));
         phBuilder.setAdjRibInType(AdjRibInType.forValue(1));
         phBuilder.setIpv4(false);
         phBuilder.setAddress(new IpAddress(new Ipv6Address("2001::1")));
@@ -115,7 +121,7 @@ public class AbstractBmpPerPeerMessageParserTest {
         phBuilder.setTimestampSec(new Timestamp(0L));
         phBuilder.setTimestampMicro(new Timestamp(0L));
 
-        assertEquals(perHeader, phBuilder.build());
+        assertEquals(phBuilder.build(), perHeader);
 
         final ByteBuf aggregator = Unpooled.buffer();
         phBuilder.setTimestampSec(null);