BUG-45 : migrated Origin path attribute to generated source code. 88/1288/2
authorDana Kutenicsova <dkutenic@cisco.com>
Thu, 19 Sep 2013 12:29:05 +0000 (14:29 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Thu, 19 Sep 2013 12:52:15 +0000 (14:52 +0200)
Change-Id: Iec25622d652888b7373eee5a131b13a106af6aea
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
18 files changed:
bgp/concepts/pom.xml
bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BGPOrigin.java [deleted file]
bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BaseBGPObjectState.java
bgp/concepts/src/main/yang/bgp-types.yang [new file with mode: 0644]
bgp/concepts/src/test/java/org/opendaylight/protocol/bgp/concepts/TableTypeTest.java
bgp/parser-api/pom.xml
bgp/parser-api/src/main/yang/bgp-message.yang
bgp/parser-api/src/test/java/org/opendaylight/protocol/bgp/parser/APITest.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/BGPUpdateEventBuilder.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/update/PathAttributeParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/PathAttributeParserTest.java [new file with mode: 0644]
bgp/parser-mock/src/test/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMockTest.java
bgp/util/src/main/java/org/opendaylight/protocol/bgp/util/BGPNodeImpl.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/LinkTest.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/NodeTest.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/PrefixTest.java
bgp/util/src/test/java/org/opendaylight/protocol/bgp/util/RouteTest.java

index 665d182424584f7fda1510f69910baa1426067fd..9c6aa60aa95edd3b1cd97396251bd39b6f646eaa 100644 (file)
                        <artifactId>guava</artifactId>
                        <version>${guava.version}</version>
                </dependency>
+                <!--
+            FIXME: this is in support of the generated code. This should not
+                   be here, but the plugin should bring it in.
+        -->
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-binding</artifactId>
+            <version>0.5.7-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-common</artifactId>
+            <version>0.5.7-SNAPSHOT</version>
+        </dependency>
+
+        <!--
+             FIXME: these are IETF models which are pre-generated in SAL infra.
+                    This should not be here, but rather should somehow be
+                    discovered by the plugin.
+        -->
+        <dependency>
+            <groupId>org.opendaylight.yangtools.model</groupId>
+            <artifactId>ietf-inet-types</artifactId>
+            <version>2010.09.24-SNAPSHOT</version>
+        </dependency>
        </dependencies>
 
        <build>
                <plugins>
                        <plugin>
+               <groupId>org.opendaylight.yangtools</groupId>
+               <artifactId>yang-maven-plugin</artifactId>
+               <version>0.5.7-SNAPSHOT</version>
+               <executions>
+                   <execution>
+                       <goals>
+                           <goal>generate-sources</goal>
+                       </goals>
+                       <configuration>
+                           <yangFilesRootDir>src/main/yang</yangFilesRootDir>
+                           <codeGenerators>
+                               <generator>
+                                   <codeGeneratorClass>
+                                       org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+                                   </codeGeneratorClass>
+                                   <outputBaseDir>
+                                       target/generated-sources/sal
+                                   </outputBaseDir>
+                               </generator>
+                           </codeGenerators>
+                           <inspectDependencies>true</inspectDependencies>
+                       </configuration>
+                   </execution>
+               </executions>
+               <dependencies>
+                   <dependency>
+                       <groupId>org.opendaylight.yangtools</groupId>
+                       <artifactId>maven-sal-api-gen-plugin</artifactId>
+                       <version>0.5.7-SNAPSHOT</version>
+                       <type>jar</type>
+                   </dependency>
+               </dependencies>
+           </plugin>
+                       <plugin>
                                <groupId>org.apache.felix</groupId>
                                <artifactId>maven-bundle-plugin</artifactId>
                                <version>${maven.bundle.version}</version>
diff --git a/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BGPOrigin.java b/bgp/concepts/src/main/java/org/opendaylight/protocol/bgp/concepts/BGPOrigin.java
deleted file mode 100644 (file)
index 40069a4..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2013 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.protocol.bgp.concepts;
-
-/**
- * 
- * Values of BGP Origin Path Attribute.
- * 
- */
-public enum BGPOrigin {
-       IGP, EGP, INCOMPLETE
-}
index 5762eb5857b875e157c25b872b2c03f1a378ab8a..72f9a686715c9559375688883df976a89364006c 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.protocol.bgp.concepts;
 
 import org.opendaylight.protocol.concepts.State;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+
 import com.google.common.base.Objects;
 import com.google.common.base.Objects.ToStringHelper;
 
@@ -21,7 +23,7 @@ public class BaseBGPObjectState implements State {
 
        private static final long serialVersionUID = 2371691093534458869L;
 
-       private final BGPOrigin origin;
+       private final BgpOrigin origin;
        private final BGPAggregator aggregator;
 
        /**
@@ -30,7 +32,7 @@ public class BaseBGPObjectState implements State {
         * @param origin {@link BGPOrigin}
         * @param aggregator {@link BGPAggregator}
         */
-       public BaseBGPObjectState(final BGPOrigin origin, final BGPAggregator aggregator) {
+       public BaseBGPObjectState(final BgpOrigin origin, final BGPAggregator aggregator) {
                super();
                this.origin = origin;
                this.aggregator = aggregator;
@@ -46,7 +48,7 @@ public class BaseBGPObjectState implements State {
         * 
         * @return the value of the ORIGIN attribute
         */
-       public final BGPOrigin getOrigin() {
+       public final BgpOrigin getOrigin() {
                return this.origin;
        }
 
diff --git a/bgp/concepts/src/main/yang/bgp-types.yang b/bgp/concepts/src/main/yang/bgp-types.yang
new file mode 100644 (file)
index 0000000..1cb9782
--- /dev/null
@@ -0,0 +1,45 @@
+module bgp-types {
+       yang-version 1;
+       namespace "urn:opendaylight:params:xml:ns:yang:bgp-types";
+       prefix "bgp-t";
+
+       import ietf-inet-types {
+               prefix inet;
+               revision-date 2010-09-24;
+       }
+
+       organization "Cisco Systems, Inc.";
+       contact "Dana Kutenicsova <dkutenic@cisco.com>";
+
+       description
+               "This module contains the base concepts contained in RFC4271 and RFC4760.
+
+               Copyright (c)2013 Cisco Systems, Inc. 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";
+
+       revision "2013-09-19" {
+               description
+                       "Initial revision.";
+               reference "RFC4271, RFC4760";
+       }
+
+       typedef bgp-origin {
+               reference "http://tools.ietf.org/html/rfc4271#section-5";
+               description "Values of BGP Origin Path Attribute.";
+               type enumeration {
+                       enum igp {
+                               value 0;
+                       }
+                       enum egp {
+                               value 1;
+                       }
+                       enum incomplete {
+                               value 2;
+                       }
+               }
+       }
+}
\ No newline at end of file
index 388ae0241fa5b02590a1d703d258b1fd72382d80..ec3e4bb9d090b1a95d9d31845f7224981fe35b52 100644 (file)
@@ -14,13 +14,8 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
-import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
-import org.opendaylight.protocol.bgp.concepts.BGPTableType;
-import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
-
 import org.opendaylight.protocol.concepts.IPv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 public class TableTypeTest {
 
@@ -58,16 +53,16 @@ public class TableTypeTest {
 
        @Test
        public void testOrigin() {
-               final BGPOrigin or = BGPOrigin.EGP;
-               assertEquals(or.name(), "EGP");
+               final BgpOrigin or = BgpOrigin.Egp;
+               assertEquals(or.name(), "Egp");
        }
 
        @Test
        public void testBaseBGPObjectState() {
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.INCOMPLETE, null);
-               final BaseBGPObjectState state1 = new BaseBGPObjectState(BGPOrigin.INCOMPLETE, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, null);
+               final BaseBGPObjectState state1 = new BaseBGPObjectState(BgpOrigin.Incomplete, null);
                assertNull(state.getAggregator());
-               assertEquals(BGPOrigin.INCOMPLETE, state.getOrigin());
+               assertEquals(BgpOrigin.Incomplete, state.getOrigin());
                assertEquals(state.toString(), state1.toString());
 
                final BaseBGPObjectState s = new BaseBGPObjectState(state);
index c0c65b4baebc6301e830dcd09e9a196ba4f0b37b..3c366d451b8d424a7f97c082fd614c29c9c87665 100644 (file)
                        <artifactId>slf4j-api</artifactId>
                        <version>${slf4j.version}</version>
         </dependency>
-
-        <!--
-            FIXME: this is in support of the generated code. This should not
-                   be here, but the plugin should bring it in.
-        -->
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-binding</artifactId>
-            <version>${yangtools.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-common</artifactId>
-            <version>${yangtools.version}</version>
-        </dependency>
-
-        <!--
-             FIXME: these are IETF models which are pre-generated in SAL infra.
-                    This should not be here, but rather should somehow be
-                    discovered by the plugin.
-        -->
-        <dependency>
-            <groupId>org.opendaylight.yangtools.model</groupId>
-            <artifactId>ietf-inet-types</artifactId>
-            <version>2010.09.24-SNAPSHOT</version>
-        </dependency>
-        <!--dependency>
-            <groupId>org.opendaylight.yangtools.model</groupId>
-            <artifactId>ietf-yang-types</artifactId>
-            <version>2010.09.24-SNAPSHOT</version>
-        </dependency-->
        </dependencies>
 
        <build>
index dbe246366a6ff30d6d2f385438b5288b85e208d1..e642be70462b227d1163854731cf05542ac918ee 100644 (file)
@@ -8,6 +8,8 @@ module bgp-message {
                revision-date 2010-09-24;
        }
 
+       import bgp-types { prefix bgp-t; }
+
        organization "Cisco Systems, Inc.";
        contact "Dana Kutenicsova <dkutenic@cisco.com>";
 
@@ -28,21 +30,6 @@ module bgp-message {
                reference "RFC4271, RFC4893";
        }
 
-       typedef origin-value {
-               reference "http://tools.ietf.org/html/rfc4271#section-5";
-               type enumeration {
-                       enum igp {
-                               value 0;
-                       }
-                       enum egp {
-                               value 1;
-                       }
-                       enum incomplete {
-                               value 2;
-                       }
-               }
-       }
-
        typedef protocol-version {
                type uint8 {
                        range 1..7;
@@ -113,7 +100,7 @@ module bgp-message {
                        container origin {
                                reference "http://tools.ietf.org/html/rfc4271#section-5.1.1";
                                leaf value {
-                                       type origin-value;
+                                       type bgp-t:bgp-origin;
                                        mandatory true;
                                }
                        }
index 42980a381fc9c3c4cda275f4871927e6147ce40b..4eee1a32d3ebd0c58088b431c8a5ac7d30b494c4 100644 (file)
@@ -20,7 +20,6 @@ import java.util.Map;
 
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
@@ -51,26 +50,27 @@ import org.opendaylight.protocol.concepts.Metric;
 import org.opendaylight.protocol.concepts.TEMetric;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
 public class APITest {
 
-       BaseBGPObjectState objState = new BaseBGPObjectState(BGPOrigin.EGP, null);
+       BaseBGPObjectState objState = new BaseBGPObjectState(BgpOrigin.Egp, null);
        NetworkObjectState netObjState = new NetworkObjectState(null, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
 
        @Test
        public void testAPI() {
                final BGPRouteState<IPv4Address> route1 = new BGPRouteState<IPv4Address>(this.objState, new NetworkRouteState<IPv4Address>(new IPv4NextHop(IPv4.FAMILY.addressForString("192.168.5.4"))));
-               final BGPRouteState<IPv4Address> route2 = new BGPRouteState<IPv4Address>(new BaseBGPObjectState(BGPOrigin.IGP, null), new NetworkRouteState<IPv4Address>(new IPv4NextHop(IPv4.FAMILY.addressForString("172.168.5.42"))));
+               final BGPRouteState<IPv4Address> route2 = new BGPRouteState<IPv4Address>(new BaseBGPObjectState(BgpOrigin.Igp, null), new NetworkRouteState<IPv4Address>(new IPv4NextHop(IPv4.FAMILY.addressForString("172.168.5.42"))));
 
                assertEquals(route1, route1.newInstance());
                assertNotSame(route1.hashCode(), new BGPRouteState<IPv4Address>(route2).hashCode());
                assertEquals(route1.toString(), route1.toString());
                assertNull(route1.getAggregator());
                assertNotNull(route1.getObjectState().getNextHop());
-               assertEquals(route1.getOrigin(), BGPOrigin.EGP);
+               assertEquals(route1.getOrigin(), BgpOrigin.Egp);
 
                final BGPParsingException e = new BGPParsingException("Some error message.");
                assertEquals("Some error message.", e.getError());
@@ -85,7 +85,7 @@ public class APITest {
                final NetworkPrefixState state = new NetworkPrefixState(this.netObjState, Sets.<RouteTag> newTreeSet(), null);
 
                final BGPPrefixState ipv4 = new BGPPrefixState(this.objState, state);
-               final BGPPrefixState ipv6 = new BGPPrefixState(new BaseBGPObjectState(BGPOrigin.EGP, null), state);
+               final BGPPrefixState ipv6 = new BGPPrefixState(new BaseBGPObjectState(BgpOrigin.Egp, null), state);
 
                assertEquals(ipv4.toString(), ipv4.newInstance().toString());
                assertNotSame(ipv4, new BGPPrefixState(ipv6));
index 1fe1ba22795333d36f65f01e2e33cd7653faa9b6..75b48afc52d35b5ad837e6ad539eccb4cf5beab5 100644 (file)
@@ -19,12 +19,20 @@ import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
 import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.concepts.IPv4NextHop;
 import org.opendaylight.protocol.bgp.concepts.IPv6NextHop;
+import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
+import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
+import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
+import org.opendaylight.protocol.bgp.linkstate.NetworkLinkImpl;
+import org.opendaylight.protocol.bgp.linkstate.NetworkNodeImpl;
+import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
+import org.opendaylight.protocol.bgp.linkstate.NetworkPrefixState;
+import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
+import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.BGPUpdateEvent;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
@@ -35,21 +43,13 @@ import org.opendaylight.protocol.bgp.util.BGPIPv6PrefixImpl;
 import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl;
 import org.opendaylight.protocol.bgp.util.BGPLinkImpl;
 import org.opendaylight.protocol.bgp.util.BGPNodeImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.IPv6Address;
 import org.opendaylight.protocol.concepts.Prefix;
-import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
-import org.opendaylight.protocol.bgp.linkstate.NetworkPrefixState;
-import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
-import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.NetworkLinkImpl;
-import org.opendaylight.protocol.bgp.linkstate.NetworkNodeImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
@@ -126,7 +126,7 @@ public class BGPUpdateEventBuilder {
 
        private Set<BGPObject> fillAddedObjects(final List<PathAttribute> pathAttributes, final Set<Prefix<IPv4Address>> nlri)
                        throws BGPParsingException {
-               BGPOrigin origin = null;
+               BgpOrigin origin = null;
                ASPath aspath = null;
                IPv4NextHop nextHop = null;
                BGPAggregator aggregator = null;
@@ -134,8 +134,8 @@ public class BGPUpdateEventBuilder {
                final Set<Community> comm = Sets.newHashSet();
                final Map<Integer, ByteList> linkstate = Maps.newHashMap();
                for (final PathAttribute pa : pathAttributes) {
-                       if (pa.getValue() instanceof BGPOrigin) {
-                               origin = (BGPOrigin) pa.getValue();
+                       if (pa.getValue() instanceof BgpOrigin) {
+                               origin = (BgpOrigin) pa.getValue();
                        } else if (pa.getValue() instanceof ASPath) {
                                aspath = (ASPath) pa.getValue();
                        } else if (pa.getValue() instanceof IPv4NextHop) {
index dd47f81c9d82f2ef0a8c8794f106972614e91f4e..b92600dce577345fc54593a374c24e4e63e5136c 100644 (file)
@@ -11,10 +11,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-
 import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.ClusterIdentifier;
 import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
@@ -29,10 +27,12 @@ import org.opendaylight.protocol.bgp.parser.impl.MPReach;
 import org.opendaylight.protocol.bgp.parser.impl.PathAttribute;
 import org.opendaylight.protocol.bgp.parser.impl.PathAttribute.TypeCode;
 import org.opendaylight.protocol.bgp.parser.impl.message.update.AsPathSegmentParser.SegmentType;
-import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.concepts.ASNumber;
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.NetworkAddress;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.common.primitives.UnsignedBytes;
@@ -140,23 +140,11 @@ public class PathAttributeParser {
         * @throws BGPParsingException if the Origin value is unknown
         * @throws BGPDocumentedException
         */
-       private static BGPOrigin parseOrigin(final byte[] bytes) throws BGPDocumentedException {
-               final int value = UnsignedBytes.toInt(bytes[0]);
-               BGPOrigin origin;
-               switch (value) {
-               case 0:
-                       origin = BGPOrigin.IGP;
-                       break;
-               case 1:
-                       origin = BGPOrigin.EGP;
-                       break;
-               case 2:
-                       origin = BGPOrigin.INCOMPLETE;
-                       break;
-               default:
+       private static BgpOrigin parseOrigin(final byte[] bytes) throws BGPDocumentedException {
+               final BgpOrigin origin = BgpOrigin.forValue(UnsignedBytes.toInt(bytes[0]));
+               if (origin == null)
                        throw new BGPDocumentedException("Unknown Origin type.", BGPError.ORIGIN_ATTR_NOT_VALID, new byte[] { (byte) 0x01, (byte) 0x01,
                                        bytes[0] });
-               }
                return origin;
        }
 
index 83b899ce75ac1c6c88575f8ea769dca9945ba54e..09ceef540190702b7e6401448f2b7ba1c0c557ab 100644 (file)
@@ -26,7 +26,6 @@ import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
 import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
@@ -79,6 +78,7 @@ import org.opendaylight.protocol.concepts.Identifier;
 import org.opendaylight.protocol.concepts.Metric;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
@@ -218,7 +218,7 @@ public class BGPParserTest {
                // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
 
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.IGP, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
                final NetworkRouteState<IPv4Address> routeState = new NetworkRouteState<>(new NetworkObjectState(asPath, comms, Collections.<ExtendedCommunity> emptySet()), nextHop);
 
                // check API message
@@ -336,7 +336,7 @@ public class BGPParserTest {
                // TypeCode.CLUSTER_LIST, true, false, false, false, clusters);
                // assertEquals(clusterAttr, attrs.get(4));
 
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.IGP, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
                final NetworkRouteState<IPv6Address> routeState = new NetworkRouteState<>(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
 
                // check API message
@@ -447,7 +447,7 @@ public class BGPParserTest {
                // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1);
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
 
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.INCOMPLETE, aggregator);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Incomplete, aggregator);
                final NetworkRouteState<IPv4Address> routeState = new NetworkRouteState<>(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
 
                // check API message
@@ -522,7 +522,7 @@ public class BGPParserTest {
                final IPv4NextHop nextHop = IPv4NextHop.forString("3.3.3.3");
 
                final Set<ExtendedCommunity> comms = Sets.newHashSet((ExtendedCommunity) new Inet4SpecificExtendedCommunity(false, 4, IPv4.FAMILY.addressForString("192.168.1.0"), new byte[] {
-                       0x12, 0x34 }));
+                               0x12, 0x34 }));
 
                // check path attributes
 
@@ -551,7 +551,7 @@ public class BGPParserTest {
                // final Set<IPv4Prefix> nlri = Sets.newHashSet(pref1, pref2, pref3);
                // assertEquals(nlri, ret.getBgpUpdateMessageBuilder().getNlri());
 
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.EGP, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Egp, null);
                final NetworkRouteState<IPv4Address> routeState = new NetworkRouteState<>(new NetworkObjectState(ASPath.EMPTY, Collections.<Community> emptySet(), comms), nextHop);
 
                // check API message
@@ -879,7 +879,7 @@ public class BGPParserTest {
 
                // network object state
                final NetworkObjectState objState = new NetworkObjectState(ASPath.EMPTY, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.IGP, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
 
                // network link state
                final DefaultingTypesafeContainer<Metric<?>> container = new DefaultingTypesafeContainer<Metric<?>>();
@@ -1011,7 +1011,7 @@ public class BGPParserTest {
 
                // network object state
                final NetworkObjectState objState = new NetworkObjectState(ASPath.EMPTY, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.IGP, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
                final NetworkNodeState nstate = new NetworkNodeState(objState, Collections.<TopologyIdentifier> emptySet(), Collections.<ISISAreaIdentifier> emptySet(), false, false, false, false, Collections.<RouterIdentifier> emptySet(), null);
 
                // network link state
diff --git a/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/PathAttributeParserTest.java b/bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/PathAttributeParserTest.java
new file mode 100644 (file)
index 0000000..11870ba
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2013 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.protocol.bgp.parser.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
+import org.opendaylight.protocol.bgp.parser.BGPParsingException;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.PathAttributeParser;
+
+/*
+ * To test incorrect values.
+ */
+public class PathAttributeParserTest {
+
+       @Test
+       public void testOriginParser() {
+               try {
+                       PathAttributeParser.parseAttribute(new byte[] { 0x40, 0x01, 0x01, 0x04 });
+                       fail("This needs to fail.");
+               } catch (final BGPDocumentedException e) {
+                       assertEquals("Unknown Origin type.", e.getMessage());
+                       assertArrayEquals(new byte[] { 0x01, 0x01, 0x04 }, e.getData());
+               } catch (final BGPParsingException e) {
+                       fail("This exception should not occur.");
+               }
+       }
+}
index 33145011b5e3f510963715249e2ed6786caedcaf..5fd4db656b42628fe484639d38731cc3827c6ec7 100644 (file)
@@ -28,7 +28,6 @@ import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.ASPath;
 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
@@ -53,6 +52,7 @@ import org.opendaylight.protocol.concepts.Identifier;
 import org.opendaylight.protocol.concepts.Prefix;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -83,7 +83,7 @@ public class BGPMessageParserMockTest {
        public void testGetUpdateMessage() throws DeserializerException, DocumentedException, IOException {
                final Map<byte[], List<BGPMessage>> updateMap = Maps.newHashMap();
                for (int i = 0; i < this.inputBytes.length; i++) {
-                       updateMap.put(this.inputBytes[i], Lists.newArrayList((BGPMessage)this.messages.get(i)));
+                       updateMap.put(this.inputBytes[i], Lists.newArrayList((BGPMessage) this.messages.get(i)));
                }
 
                final BGPMessageParserMock mockParser = new BGPMessageParserMock(updateMap);
@@ -105,7 +105,7 @@ public class BGPMessageParserMockTest {
        public void testGetUpdateMessageException() throws DeserializerException, DocumentedException, IOException {
                final Map<byte[], List<BGPMessage>> updateMap = Maps.newHashMap();
                for (int i = 0; i < this.inputBytes.length; i++) {
-                       updateMap.put(this.inputBytes[i], Lists.newArrayList((BGPMessage)this.messages.get(i)));
+                       updateMap.put(this.inputBytes[i], Lists.newArrayList((BGPMessage) this.messages.get(i)));
                }
 
                final BGPMessageParserMock mockParser = new BGPMessageParserMock(updateMap);
@@ -150,7 +150,7 @@ public class BGPMessageParserMockTest {
                final Set<BGPObject> addedObjects = new HashSet<BGPObject>();
 
                final NetworkRouteState<IPv6Address> nstate = new NetworkRouteState<>(new NetworkObjectState(asPath, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet()), nextHop);
-               final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.IGP, null);
+               final BaseBGPObjectState state = new BaseBGPObjectState(BgpOrigin.Igp, null);
 
                final BGPRoute<IPv6Address> route1 = new BGPIPv6RouteImpl(pref1, state, nstate);
                final BGPRoute<IPv6Address> route2 = new BGPIPv6RouteImpl(pref2, state, nstate);
@@ -174,7 +174,7 @@ public class BGPMessageParserMockTest {
 
                final byte[] input = new byte[] { 5, 8, 13, 21 };
 
-               openMap.put(input, Lists.newArrayList((BGPMessage)new BGPOpenMessage(new ASNumber(30), (short) 30, null, params)));
+               openMap.put(input, Lists.newArrayList((BGPMessage) new BGPOpenMessage(new ASNumber(30), (short) 30, null, params)));
 
                final BGPMessageParserMock mockParser = new BGPMessageParserMock(openMap);
 
index 3e9ee8ace0934c05fa0f336d0afe84dc1b3c6522..8fb6532a9298765d92cdb6260256b2005555b88a 100644 (file)
@@ -7,15 +7,12 @@
  */
 package org.opendaylight.protocol.bgp.util;
 
-import org.opendaylight.protocol.bgp.concepts.BGPAggregator;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
+import org.opendaylight.protocol.bgp.linkstate.NetworkNodeState;
+import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
 import org.opendaylight.protocol.bgp.parser.BGPNode;
 import org.opendaylight.protocol.bgp.parser.BGPNodeState;
 
-import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.NetworkNode;
-import org.opendaylight.protocol.bgp.linkstate.NetworkNodeState;
 import com.google.common.base.Objects.ToStringHelper;
 
 /**
@@ -32,10 +29,8 @@ public final class BGPNodeImpl extends AbstractBGPObject implements BGPNode {
        /**
         * Creates this object with given arguments.
         * 
-        * @param origin {@link BGPOrigin}
-        * @param aggregator {@link BGPAggregator}
         * @param nodeIdentifier {@link NodeIdentifier}
-        * @param nodeAttributes {@link NetworkNode}
+        * @param nodeState {@link NetworkNodeState}
         */
        public BGPNodeImpl(final BaseBGPObjectState base, final NodeIdentifier nodeIdentifier, final NetworkNodeState nodeState) {
                super(new BGPNodeState(base, nodeState));
index 37880ce06662fa16b31c4970a3f68f22d9ee6340..003f662d0402c4a8af18697dc6db480e911a5709 100644 (file)
@@ -12,27 +12,24 @@ import static org.junit.Assert.assertEquals;
 import java.util.Collections;
 
 import org.junit.Test;
-
-import org.opendaylight.protocol.concepts.Metric;
+import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
+import org.opendaylight.protocol.bgp.concepts.Community;
+import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
 import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.LinkProtectionType;
-import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.NetworkLinkState;
 import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
-
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
-import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
-import org.opendaylight.protocol.bgp.concepts.Community;
-import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
-import org.opendaylight.protocol.bgp.util.BGPLinkImpl;
+import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
+import org.opendaylight.protocol.concepts.Metric;
 import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 public class LinkTest {
 
        @Test
        public void testLinkImpl() {
 
-               final BaseBGPObjectState state1 = new BaseBGPObjectState(BGPOrigin.EGP, null);
+               final BaseBGPObjectState state1 = new BaseBGPObjectState(BgpOrigin.Egp, null);
                final NetworkObjectState empty = new NetworkObjectState(null, Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
                final NetworkLinkState nstate1 = new NetworkLinkState(empty, new DefaultingTypesafeContainer<Metric<?>>(), null, LinkProtectionType.UNPROTECTED, null, null, null);
 
index 1c32f6d7516094a972f6056e587852199353a0e6..ff41a6932e417e65181583a31ac4ca1f83f1dc3e 100644 (file)
@@ -13,25 +13,23 @@ import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
-import org.opendaylight.protocol.bgp.util.BGPNodeImpl;
-
 import org.opendaylight.protocol.bgp.linkstate.NetworkNodeState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 public class NodeTest {
 
        @Test
        public void testNodeImpl() {
-               final BGPNodeImpl node1 = new BGPNodeImpl(new BaseBGPObjectState(BGPOrigin.INCOMPLETE, null), null, NetworkNodeState.EMPTY);
-               final BGPNodeImpl node2 = new BGPNodeImpl(new BaseBGPObjectState(BGPOrigin.EGP, null), null, NetworkNodeState.EMPTY);
+               final BGPNodeImpl node1 = new BGPNodeImpl(new BaseBGPObjectState(BgpOrigin.Incomplete, null), null, NetworkNodeState.EMPTY);
+               final BGPNodeImpl node2 = new BGPNodeImpl(new BaseBGPObjectState(BgpOrigin.Egp, null), null, NetworkNodeState.EMPTY);
 
                assertFalse(node1.equals(node2));
                assertNotSame(node1.hashCode(), node2.hashCode());
                assertEquals(node1.toString(), node1.toString());
                assertNull(node1.currentState().getAggregator());
-               assertEquals(node1.currentState().getOrigin(), BGPOrigin.INCOMPLETE);
+               assertEquals(node1.currentState().getOrigin(), BgpOrigin.Incomplete);
                assertEquals(node1.getNodeIdentifier(), node2.getNodeIdentifier());
-               assertEquals(node2, new BGPNodeImpl(new BaseBGPObjectState(BGPOrigin.EGP, null), null, NetworkNodeState.EMPTY));
+               assertEquals(node2, new BGPNodeImpl(new BaseBGPObjectState(BgpOrigin.Egp, null), null, NetworkNodeState.EMPTY));
        }
 }
index c020d396b6572fda27e67259cd8fc6481e9b2507..72078dd921b01cb88f27baf1a4413666d7624501 100644 (file)
@@ -14,28 +14,26 @@ import java.util.Collections;
 
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.ASPath;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
 import org.opendaylight.protocol.bgp.concepts.Community;
 import org.opendaylight.protocol.bgp.concepts.ExtendedCommunity;
-import org.opendaylight.protocol.bgp.util.BGPIPv4PrefixImpl;
-import org.opendaylight.protocol.bgp.util.BGPIPv6PrefixImpl;
-
-import org.opendaylight.protocol.concepts.ASNumber;
-import org.opendaylight.protocol.concepts.IPv4;
-import org.opendaylight.protocol.concepts.IPv6;
+import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
+import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
+import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
+import org.opendaylight.protocol.bgp.linkstate.NetworkPrefixState;
 import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.OSPFRouterIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.RouteTag;
-import org.opendaylight.protocol.bgp.linkstate.NetworkObjectState;
-import org.opendaylight.protocol.bgp.linkstate.NetworkPrefixState;
-import org.opendaylight.protocol.bgp.linkstate.IPv4PrefixIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.IPv6PrefixIdentifier;
+import org.opendaylight.protocol.concepts.ASNumber;
+import org.opendaylight.protocol.concepts.IPv4;
+import org.opendaylight.protocol.concepts.IPv6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 public class PrefixTest {
-       final BaseBGPObjectState base = new BaseBGPObjectState(BGPOrigin.EGP, null);
+       final BaseBGPObjectState base = new BaseBGPObjectState(BgpOrigin.Egp, null);
        final NetworkObjectState state = new NetworkObjectState(new ASPath(Lists.newArrayList(new ASNumber(10L))), Collections.<Community> emptySet(), Collections.<ExtendedCommunity> emptySet());
        final NetworkPrefixState prefixState = new NetworkPrefixState(this.state, Sets.<RouteTag> newTreeSet(), null);
 
index d54127be89bec38bd85720602207430c6162dfc3..025de8a70eca500e54c7c360a7527012ffb2dd49 100644 (file)
@@ -11,22 +11,19 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotSame;
 
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
 import org.opendaylight.protocol.bgp.concepts.IPv4NextHop;
 import org.opendaylight.protocol.bgp.concepts.IPv6NextHop;
-import org.opendaylight.protocol.bgp.util.BGPIPv4RouteImpl;
-import org.opendaylight.protocol.bgp.util.BGPIPv6RouteImpl;
-
+import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
 import org.opendaylight.protocol.concepts.IPv4;
 import org.opendaylight.protocol.concepts.IPv4Address;
 import org.opendaylight.protocol.concepts.IPv6;
 import org.opendaylight.protocol.concepts.IPv6Address;
-import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
 
 public class RouteTest {
 
-       BaseBGPObjectState base = new BaseBGPObjectState(BGPOrigin.EGP, null);
+       BaseBGPObjectState base = new BaseBGPObjectState(BgpOrigin.Egp, null);
        final NetworkRouteState<IPv4Address> prefix4State = new NetworkRouteState<>(IPv4NextHop.forString("128.54.8.9"));
        final NetworkRouteState<IPv6Address> prefix6State = new NetworkRouteState<>(IPv6NextHop.forString("2001::4"));
        final BGPIPv4RouteImpl r4 = new BGPIPv4RouteImpl(IPv4.FAMILY.prefixForString("172.168.4.6/24"), this.base, this.prefix4State);