Mass-convert all compontents to use -no-zone addresses
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / ComplementaryTest.java
index fb3703d16263974739bb2ab2fba58d1097885357..8f761fdc83633aac8f10af43b45c0d8bef626442 100644 (file)
 package org.opendaylight.protocol.bgp.parser.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Set;
 
+import java.util.ArrayList;
+import java.util.List;
 import org.junit.Test;
-import org.opendaylight.protocol.bgp.concepts.ASSpecificExtendedCommunity;
-import org.opendaylight.protocol.bgp.concepts.Inet4SpecificExtendedCommunity;
-import org.opendaylight.protocol.bgp.concepts.OpaqueExtendedCommunity;
-import org.opendaylight.protocol.bgp.concepts.RouteOriginCommunity;
-import org.opendaylight.protocol.bgp.concepts.RouteTargetCommunity;
-import org.opendaylight.protocol.bgp.linkstate.IPv4InterfaceIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.ISISLANIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.ISISRouterIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.InterfaceIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.LinkAnchor;
-import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.NodeIdentifier;
-import org.opendaylight.protocol.bgp.linkstate.NodeIdentifierFactory;
-import org.opendaylight.protocol.bgp.linkstate.SourceProtocol;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunitiesParser;
-import org.opendaylight.protocol.bgp.parser.impl.message.update.MPReachParser;
-import org.opendaylight.protocol.concepts.ASNumber;
-import org.opendaylight.protocol.concepts.IPv4;
-import org.opendaylight.protocol.concepts.IPv4Address;
-import org.opendaylight.protocol.concepts.ISOSystemIdentifier;
-import org.opendaylight.protocol.framework.DeserializerException;
-import org.opendaylight.protocol.framework.DocumentedException;
-
-import com.google.common.collect.Sets;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.AggregatorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapability.RestartFlags;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.GracefulRestartCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.TablesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpAggregator;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv6AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 public class ComplementaryTest {
 
-       @Test
-       public void testBGPAggregatorImpl() {
-               final BGPAggregatorImpl<IPv4Address> ipv4 = new BGPAggregatorImpl<IPv4Address>(new ASNumber(5524), IPv4.FAMILY.addressForString("124.55.42.1"));
-               final BGPAggregatorImpl<IPv4Address> ipv4i = new BGPAggregatorImpl<IPv4Address>(new ASNumber(5525), IPv4.FAMILY.addressForString("124.55.42.1"));
+    @Test
+    public void testBGPParameter() {
+
+        final MultiprotocolCapability cap = new MultiprotocolCapabilityBuilder().setAfi(Ipv6AddressFamily.class)
+                .setSafi(UnicastSubsequentAddressFamily.class).build();
+        final CParameters tlv1 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
+            .setMultiprotocolCapability(cap).build()).build();
+        final MultiprotocolCapability cap1 = new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class)
+                .setSafi(UnicastSubsequentAddressFamily.class).build();
+        final CParameters tlv2 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
+            .setMultiprotocolCapability(cap1).build()).build();
+
+        final List<Tables> tt = new ArrayList<>();
+        tt.add(new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+            .build());
+        tt.add(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+            .build());
+
+        final GracefulRestartCapability tlv3 = new GracefulRestartCapabilityBuilder().setRestartFlags(
+            new RestartFlags(Boolean.FALSE)).setRestartTime(Uint16.ZERO).setTables(tt).build();
+
+        final CParameters tlv4 = new CParametersBuilder().setAs4BytesCapability(
+            new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(40))).build()).build();
+
+        assertFalse(tlv3.getRestartFlags().isRestartState());
+
+        assertEquals(0, tlv3.getRestartTime().intValue());
+
+        assertNotEquals(tlv1, tlv2);
+
+        assertNotSame(tlv1.hashCode(), tlv3.hashCode());
+
+        assertNotSame(tlv2.toString(), tlv3.toString());
+
+        assertEquals(tlv3.getTables(), tt);
+
+        assertEquals(cap.getSafi(), cap1.getSafi());
+
+        assertNotSame(cap.getAfi(), cap1.getAfi());
 
-               assertNotSame(ipv4.hashCode(), ipv4i.hashCode());
+        assertEquals(40, tlv4.getAs4BytesCapability().getAsNumber().getValue().longValue());
 
-               assertEquals(ipv4, new BGPAggregatorImpl<IPv4Address>(new ASNumber(5524), IPv4.FAMILY.addressForString("124.55.42.1")));
+        assertEquals(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
+            new AsNumber(Uint32.valueOf(40))).build()).build(), tlv4);
+    }
 
-               assertNotSame(ipv4.getASNumber(), ipv4i.getASNumber());
+    @Test
+    public void testBGPAggregatorImpl() {
+        final BgpAggregator ipv4 = new AggregatorBuilder()
+                .setAsNumber(new AsNumber(Uint32.valueOf(5524)))
+                .setNetworkAddress(new Ipv4AddressNoZone("124.55.42.1"))
+                .build();
+        final BgpAggregator ipv4i = new AggregatorBuilder()
+                .setAsNumber(new AsNumber(Uint32.valueOf(5525)))
+                .setNetworkAddress(new Ipv4AddressNoZone("124.55.42.1"))
+                .build();
 
-               assertEquals(ipv4.getNetworkAddress(), ipv4i.getNetworkAddress());
-       }
+        assertNotSame(ipv4.hashCode(), ipv4i.hashCode());
 
-       @Test
-       public void testBGPLinkMP() {
-               final NodeIdentifier localnodeid = new NodeIdentifier(new ASNumber(25600, 0), null, null, new ISISRouterIdentifier(new ISOSystemIdentifier(new byte[] {
-                               0x22, 0x22, 0x22, 0x22, 0x22, 0x22 })));
-               final NodeIdentifier remotenodeid = NodeIdentifierFactory.localIdentifier(new ISISLANIdentifier(new ISOSystemIdentifier(new byte[] {
-                               0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }), (short) 1));
+        assertNotSame(ipv4.getAsNumber(), ipv4i.getAsNumber());
 
-               final InterfaceIdentifier ifaceid = new IPv4InterfaceIdentifier(IPv4.FAMILY.addressForString("10.1.1.1"));
-
-               final LinkIdentifier l = new LinkIdentifier(null, new LinkAnchor(localnodeid, ifaceid), new LinkAnchor(remotenodeid, ifaceid));
-
-               final Set<LinkIdentifier> links = Sets.newHashSet(l);
-
-               final BGPLinkMP link = new BGPLinkMP(0, SourceProtocol.Direct, true, links);
-
-               final BGPLinkMP link1 = new BGPLinkMP(0, SourceProtocol.Direct, true, Collections.<LinkIdentifier> emptySet());
-
-               assertNotSame(link.hashCode(), link1.hashCode());
-
-               assertEquals(link, new BGPLinkMP(0, SourceProtocol.Direct, true, links));
-
-               assertEquals(link.hashCode(), (new BGPLinkMP(0, SourceProtocol.Direct, true, links)).hashCode());
-
-               assertNotSame(link.toString(), link1.toString());
-       }
-
-       @Test
-       public void testBGPUpdateMessageImpl() {
-               final BGPUpdateMessageImpl msg = new BGPUpdateMessageImpl(null, null);
-               final BGPUpdateMessageImpl msg1 = new BGPUpdateMessageImpl(null, null);
-
-               assertEquals(msg, msg1);
-
-               assertEquals(msg.hashCode(), msg1.hashCode());
-
-               assertNotNull(msg.toString());
-
-               assertNull(msg.getAddedObjects());
-               assertNull(msg.getRemovedObjects());
-
-               assertNotSame(msg1, null);
-       }
-
-       @Test
-       public void testCommunitiesParser() {
-               ASSpecificExtendedCommunity as = null;
-               try {
-                       as = (ASSpecificExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 0, 5, 0, 54, 0, 0, 1, 76 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(as, new ASSpecificExtendedCommunity(false, 5, new ASNumber(54), new byte[] { 0, 0, 1, 76 }));
-
-               try {
-                       as = (ASSpecificExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 40, 5, 0, 54, 0, 0, 1, 76 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(as, new ASSpecificExtendedCommunity(true, 5, new ASNumber(54), new byte[] { 0, 0, 1, 76 }));
-
-               RouteTargetCommunity rtc = null;
-               try {
-                       rtc = (RouteTargetCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 1, 2, 0, 35, 4, 2, 8, 7 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(rtc, new RouteTargetCommunity(new ASNumber(35), new byte[] { 4, 2, 8, 7 }));
-
-               RouteOriginCommunity roc = null;
-               try {
-                       roc = (RouteOriginCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 0, 3, 0, 24, 4, 2, 8, 7 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(roc, new RouteOriginCommunity(new ASNumber(24), new byte[] { 4, 2, 8, 7 }));
-
-               Inet4SpecificExtendedCommunity sec = null;
-               try {
-                       sec = (Inet4SpecificExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 41, 6, 12, 51, 2, 5, 21, 45 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(sec, new Inet4SpecificExtendedCommunity(true, 6, IPv4.FAMILY.addressForString("12.51.2.5"), new byte[] { 21, 45 }));
-
-               OpaqueExtendedCommunity oec = null;
-               try {
-                       oec = (OpaqueExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 3, 6, 21, 45, 5, 4, 3, 1 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(oec, new OpaqueExtendedCommunity(false, 6, new byte[] { 21, 45, 5, 4, 3, 1 }));
-
-               try {
-                       oec = (OpaqueExtendedCommunity) CommunitiesParser.parseExtendedCommunity(new byte[] { 43, 6, 21, 45, 5, 4, 3, 1 });
-               } catch (final BGPDocumentedException e1) {
-                       fail("Not expected exception: " + e1);
-               }
-               assertEquals(oec, new OpaqueExtendedCommunity(true, 6, new byte[] { 21, 45, 5, 4, 3, 1 }));
-
-               try {
-                       CommunitiesParser.parseExtendedCommunity(new byte[] { 11, 11, 21, 45, 5, 4, 3, 1 });
-                       fail("Exception should have occured.");
-               } catch (final BGPDocumentedException e) {
-                       assertEquals("Could not parse Extended Community type: 11", e.getMessage());
-               }
-       }
-
-       @Test
-       public void testMPReachParser() {
-               String msg = "";
-               try {
-                       MPReachParser.parseSafi(5);
-                       fail("Exception shoul have occured.");
-               } catch (final BGPParsingException e) {
-                       msg = e.getMessage();
-               }
-               assertEquals("Subsequent Address Family Identifier: '5' not supported.", msg);
-
-               try {
-                       MPReachParser.parseAfi(6);
-                       fail("Exception should have occured.");
-               } catch (final BGPParsingException e) {
-                       msg = e.getMessage();
-               }
-               assertEquals("Address Family Identifier: '6' not supported.", msg);
-       }
-
-       @Test
-       public void testBGPHeaderParser() throws IOException {
-               final BGPMessageFactoryImpl h = new BGPMessageFactoryImpl();
-               try {
-                       h.parse(new byte[] { (byte) 0, (byte) 0 });
-                       fail("Exception should have occured.");
-               } catch (final IllegalArgumentException e) {
-                       assertEquals("Too few bytes in passed array. Passed: 2. Expected: >= 19.", e.getMessage());
-               } catch (final DeserializerException e) {
-                       fail("Not this exception should have occured:" + e);
-               } catch (final DocumentedException e) {
-                       fail("Not this exception should have occured:" + e);
-               }
-       }
-
-       @Test
-       public void testByteList() {
-               final ByteList b1 = new ByteList();
-               b1.add(new byte[] { 3, 4, 8 });
-               b1.add(new byte[] { 3, 4, 9 });
-
-               final ByteList b2 = new ByteList();
-               b2.add(new byte[] { 3, 4, 8 });
-               b2.add(new byte[] { 3, 4, 9 });
-
-               assertEquals(b1, b2);
-               assertEquals(b1.toString(), b2.toString());
-       }
-
-       @Test
-       public void testMessageParser() throws IOException {
-               final BGPMessageFactoryImpl parser = new BGPMessageFactoryImpl();
-               String ex = "";
-               try {
-                       parser.put(null);
-               } catch (final IllegalArgumentException e) {
-                       ex = e.getMessage();
-               }
-               assertEquals("BGPMessage is mandatory.", ex);
-       }
+        assertEquals(ipv4.getNetworkAddress(), ipv4i.getNetworkAddress());
+    }
 }