BUG-45 : fixed Open parser/serializer, fixed some tests, that were ignored. 76/1676/1
authorDana Kutenicsova <dkutenic@cisco.com>
Fri, 4 Oct 2013 13:17:29 +0000 (15:17 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Fri, 4 Oct 2013 13:48:58 +0000 (15:48 +0200)
Change-Id: I4cb565bbd64b1d7aaf396235fdaa6361338fba6a
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/NodeIdentifierTest.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/BGPParameterParser.java
bgp/parser-impl/src/main/java/org/opendaylight/protocol/bgp/parser/impl/message/open/CapabilityParameterParser.java
bgp/parser-impl/src/test/java/org/opendaylight/protocol/bgp/parser/impl/BGPParserTest.java
bgp/parser-mock/src/test/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMockTest.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionNegotiator.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/FSMTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserTest.java

index 253fc98352fe228e53743288bb53faf23ddf1890..bc88aa7183c22262b990ab8c6af0345097fb5b1d 100644 (file)
@@ -30,9 +30,9 @@ public class NodeIdentifierTest {
                final NodeIdentifier id3 = this.f.identifierForRouter(new IPv4RouterIdentifier(IPv4.FAMILY.addressForString("192.168.1.5")));
                final NodeIdentifier id4 = this.f.identifierForRouter(new IPv6RouterIdentifier(IPv6.FAMILY.addressForString("2001:db8:85a3::8a2e:370:7334")));
 
+               // FIXME BUG-103
                // assertEquals("HashCodes should be equal", id1.hashCode(), id2.hashCode());
-               // FIXME BUG-89
-               // assertEquals("toString should be equal", id1.toString(), id2.toString());
+               assertEquals("toString should be equal", id1.toString(), id2.toString());
                // assertEquals(id1, id2);
 
                assertNotSame(id1, id3);
@@ -71,7 +71,7 @@ public class NodeIdentifierTest {
 
        @Test
        @Ignore
-       // FIXME BUG-89
+       // FIXME BUG-103
        public void testISISRouterIdentifier() {
                final ISISRouterIdentifier is1 = new ISISRouterIdentifier(new IsoSystemIdentifier(new byte[] { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }));
                final ISISRouterIdentifier is2 = new ISISRouterIdentifier(new IsoSystemIdentifier(new byte[] { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }));
index d69bd7a3aa17db5bd85aebe7016bb7a5fd0a621c..db33ffc94cb5b042e31f2b09e6c1776ebe583fd7 100644 (file)
@@ -13,6 +13,7 @@ import java.util.List;
 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,9 +49,9 @@ public final class BGPParameterParser {
 
                byte[] value = null;
 
-               if (param instanceof CParameters) {
-                       value = CapabilityParameterParser.put((CParameters) param);
-               } else {
+               value = CapabilityParameterParser.put(param.getCParameters());
+
+               if (value == null) {
                        logger.debug("BGP Parameter not supported.");
                        return new byte[] {};
                }
@@ -80,8 +81,12 @@ public final class BGPParameterParser {
                        final int paramType = UnsignedBytes.toInt(bytes[byteOffset++]);
                        final int paramLength = UnsignedBytes.toInt(bytes[byteOffset++]);
                        if (paramType == CAPABILITIES_OPT_PARAM_TYPE) {
-                               final BgpParameters param = (BgpParameters) CapabilityParameterParser.parse(ByteArray.subByte(bytes, byteOffset,
-                                               paramLength));
+                               final CParameters cparam = CapabilityParameterParser.parse(ByteArray.subByte(bytes, byteOffset, paramLength));
+                               if (cparam == null) {
+                                       byteOffset += paramLength;
+                                       continue;
+                               }
+                               final BgpParameters param = new BgpParametersBuilder().setCParameters(cparam).build();
                                if (param != null)
                                        params.add(param);
                        } else
index b733f7b76093472f00f1235dfabfbf3154e61dc6..09015991565b165221c2177d67842d08cc69d576 100644 (file)
@@ -38,7 +38,7 @@ public final class CapabilityParameterParser {
        private static final int LENGTH_SIZE = 1; // bytes
        private static final int AFI_SIZE = 2; // bytes
        private static final int SAFI_SIZE = 1; // bytes
-       
+
        private static final int As4BytesCapability_CODE = 65;
        private static final int Multiprotocol_CODE = 1;
 
@@ -63,15 +63,17 @@ public final class CapabilityParameterParser {
                        value = putMultiProtocolParameterValue((CMultiprotocol) cap);
                        bytes = new byte[CODE_SIZE + LENGTH_SIZE + value.length];
                        bytes[0] = ByteArray.intToBytes(Multiprotocol_CODE)[Integer.SIZE / Byte.SIZE - 1];
-               //} else if (cap instanceof GracefulCapability) {
-               //      value = putGracefulParameterValue((GracefulCapability) cap);
+                       // } else if (cap instanceof GracefulCapability) {
+                       // value = putGracefulParameterValue((GracefulCapability) cap);
                } else if (cap instanceof CAs4Bytes) {
                        value = putAS4BytesParameterValue((CAs4Bytes) cap);
                        bytes = new byte[CODE_SIZE + LENGTH_SIZE + value.length];
                        bytes[0] = ByteArray.intToBytes(As4BytesCapability_CODE)[Integer.SIZE / Byte.SIZE - 1];
                }
-               bytes[1] = ByteArray.intToBytes(value.length)[Integer.SIZE / Byte.SIZE - 1];
-               System.arraycopy(value, 0, bytes, CODE_SIZE + LENGTH_SIZE, value.length);
+               if (bytes != null) {
+                       bytes[1] = ByteArray.intToBytes(value.length)[Integer.SIZE / Byte.SIZE - 1];
+                       System.arraycopy(value, 0, bytes, CODE_SIZE + LENGTH_SIZE, value.length);
+               }
                logger.trace("BGP Parameter serialized to: {}", Arrays.toString(bytes));
                return bytes;
        }
@@ -103,33 +105,34 @@ public final class CapabilityParameterParser {
                return null;
        }
 
-//     private static byte[] putGracefulParameterValue(final GracefulCapability param) {
-//             final int RESTART_FLAGS_SIZE = 4; // bits
-//             final int TIMER_SIZE = 12; // bits
-//             final int AFI_SIZE = 2; // bytes
-//             final int SAFI_SIZE = 1; // bytes
-//             final int AF_FLAGS_SIZE = 1; // bytes
-//             final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE * Byte.SIZE + AF_FLAGS_SIZE
-//                             * Byte.SIZE)
-//                             * param.getTableTypes().size())
-//                             / Byte.SIZE];
-//             if (param.isRestartFlag()) {
-//                     bytes[0] = (byte) 0x80;
-//             }
-//             int index = (RESTART_FLAGS_SIZE + TIMER_SIZE) / Byte.SIZE;
-//             for (final Entry<BGPTableType, Boolean> entry : param.getTableTypes().entrySet()) {
-//                     final byte[] a = putAfi(entry.getKey().getAddressFamily());
-//                     final byte s = putSafi(entry.getKey().getSubsequentAddressFamily());
-//                     final byte f = (entry.getValue()) ? (byte) 0x80 : (byte) 0x00;
-//                     System.arraycopy(a, 0, bytes, index, AFI_SIZE);
-//                     index += AFI_SIZE;
-//                     bytes[index] = s;
-//                     index += SAFI_SIZE;
-//                     bytes[index] = f;
-//                     index += AF_FLAGS_SIZE;
-//             }
-//             return bytes;
-//     }
+       // private static byte[] putGracefulParameterValue(final GracefulCapability param) {
+       // final int RESTART_FLAGS_SIZE = 4; // bits
+       // final int TIMER_SIZE = 12; // bits
+       // final int AFI_SIZE = 2; // bytes
+       // final int SAFI_SIZE = 1; // bytes
+       // final int AF_FLAGS_SIZE = 1; // bytes
+       // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE * Byte.SIZE +
+       // AF_FLAGS_SIZE
+       // * Byte.SIZE)
+       // * param.getTableTypes().size())
+       // / Byte.SIZE];
+       // if (param.isRestartFlag()) {
+       // bytes[0] = (byte) 0x80;
+       // }
+       // int index = (RESTART_FLAGS_SIZE + TIMER_SIZE) / Byte.SIZE;
+       // for (final Entry<BGPTableType, Boolean> entry : param.getTableTypes().entrySet()) {
+       // final byte[] a = putAfi(entry.getKey().getAddressFamily());
+       // final byte s = putSafi(entry.getKey().getSubsequentAddressFamily());
+       // final byte f = (entry.getValue()) ? (byte) 0x80 : (byte) 0x00;
+       // System.arraycopy(a, 0, bytes, index, AFI_SIZE);
+       // index += AFI_SIZE;
+       // bytes[index] = s;
+       // index += SAFI_SIZE;
+       // bytes[index] = f;
+       // index += AF_FLAGS_SIZE;
+       // }
+       // return bytes;
+       // }
 
        private static byte[] putMultiProtocolParameterValue(final CMultiprotocol param) {
                final byte[] a = putAfi(param.getMultiprotocolCapability().getAfi());
@@ -157,12 +160,14 @@ public final class CapabilityParameterParser {
                        throw new BGPParsingException("Subsequent Address Family Identifier: '"
                                        + ByteArray.bytesToInt(ByteArray.subByte(bytes, AFI_SIZE + 1, SAFI_SIZE)) + "' not supported.");
                }
-               
-               return new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(afi).setSafi(safi).build()).build();
+
+               return new CMultiprotocolBuilder().setMultiprotocolCapability(
+                               new MultiprotocolCapabilityBuilder().setAfi(afi).setSafi(safi).build()).build();
        }
 
        private static CAs4Bytes parseAS4BParameterValue(final byte[] bytes) {
-               return new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(bytes))).build()).build();
+               return new CAs4BytesBuilder().setAs4BytesCapability(
+                               new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(ByteArray.bytesToLong(bytes))).build()).build();
        }
 
        private static byte[] putAfi(final Class<? extends AddressFamily> afi) {
index c5aa97c46514730897e9825858cf10799afe7cb8..697a2a7d8d2b00eb55298aed0a75bcc9d14dddbe 100644 (file)
@@ -1102,15 +1102,13 @@ public class BGPParserTest {
         * 00 00 00 64 <- AS number
         */
        @Test
-       @Ignore
-       // FIXME BUG-100
        public void testOpenMessage() throws Exception {
                final BGPMessageFactoryImpl msgFactory = new BGPMessageFactoryImpl();
                final Open open = (Open) msgFactory.parse(inputBytes.get(13)).get(0);
                final Set<BGPTableType> types = Sets.newHashSet();
                for (final BgpParameters param : open.getBgpParameters()) {
-                       if (param instanceof CParameters) {
-                               final CParameters p = (CParameters) param;
+                       final CParameters p = param.getCParameters();
+                       if (p instanceof CMultiprotocol) {
                                final BGPTableType type = new BGPTableType(((CMultiprotocol) p).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) p).getMultiprotocolCapability().getSafi());
                                types.add(type);
                        }
index eca6d8e539c14571f31c90d38b485c99db144aa5..0a6ea7ade773670fcb5d43e5d7dc5f35deeed3c7 100644 (file)
@@ -24,7 +24,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.concepts.BGPObject;
 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
@@ -47,6 +46,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.CParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.path.attributes.as.path.SegmentsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
@@ -176,8 +176,6 @@ public class BGPMessageParserMockTest {
        }
 
        @Test
-       @Ignore
-       // FIXME BUG-100
        public void testGetOpenMessage() throws DeserializerException, DocumentedException, IOException {
                final Map<byte[], List<Notification>> openMap = Maps.newHashMap();
 
@@ -188,7 +186,7 @@ public class BGPMessageParserMockTest {
 
                final CParameters par = new CMultiprotocolBuilder().setMultiprotocolCapability(
                                new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(MplsLabeledVpnSubsequentAddressFamily.class).build()).build();
-               params.add((BgpParameters) par);
+               params.add(new BgpParametersBuilder().setCParameters(par).build());
 
                final byte[] input = new byte[] { 5, 8, 13, 21 };
 
@@ -201,11 +199,9 @@ public class BGPMessageParserMockTest {
 
                final Set<BGPTableType> result = Sets.newHashSet();
                for (final BgpParameters p : ((Open) mockParser.parse(input).get(0)).getBgpParameters()) {
-                       if (p instanceof CParameters) {
-                               final CParameters cp = ((CParameters) p);
-                               final BGPTableType t = new BGPTableType(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
-                               result.add(t);
-                       }
+                       final CParameters cp = p.getCParameters();
+                       final BGPTableType t = new BGPTableType(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
+                       result.add(t);
                }
 
                assertEquals(type, result);
index e3ff6cb7b2a87fcd6c7932303221df7de20ea054..c837d15a25b0f22a400b7f1d1f35d4d0bc88b369 100644 (file)
@@ -119,7 +119,9 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                switch (this.state) {
                case Finished:
                case Idle:
-                       throw new IllegalStateException("Unexpected state " + this.state);
+                       final Notify fsm_error = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
+                                       BGPError.FSM_ERROR.getSubcode()).build();
+                       this.channel.writeAndFlush(fsm_error);
                case OpenConfirm:
                        if (msg instanceof Keepalive) {
                                negotiationSuccessful(this.session);
@@ -136,19 +138,16 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                                final List<BgpParameters> prefs = openObj.getBgpParameters();
                                if (prefs != null && !prefs.isEmpty()) {
                                        for (final BgpParameters param : openObj.getBgpParameters()) {
-                                               if (param instanceof CParameters) {
-                                                       if (((CParameters) param) instanceof CMultiprotocol) {
-                                                               final CParameters cap = (CParameters) param;
-                                                               if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
-                                                                               && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
-                                                                       this.remotePref = openObj;
-                                                                       this.channel.writeAndFlush(new KeepaliveBuilder().build());
-                                                                       this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
-                                                                       this.state = State.OpenConfirm;
-                                                                       logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel,
-                                                                                       this.remotePref);
-                                                                       return;
-                                                               }
+                                               final CParameters cap = param.getCParameters();
+                                               if (cap instanceof CMultiprotocol) {
+                                                       if (((CMultiprotocol) cap).getMultiprotocolCapability().getAfi() == LinkstateAddressFamily.class
+                                                                       && ((CMultiprotocol) cap).getMultiprotocolCapability().getSafi() == LinkstateSubsequentAddressFamily.class) {
+                                                               this.remotePref = openObj;
+                                                               this.channel.writeAndFlush(new KeepaliveBuilder().build());
+                                                               this.session = new BGPSessionImpl(this.timer, this.listener, this.channel, this.remotePref);
+                                                               this.state = State.OpenConfirm;
+                                                               logger.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
+                                                               return;
                                                        }
                                                }
                                        }
index ad44986520fc714519b44175ef5815c2fd6e4d7c..0825350c73819b9c77c222fa628a3125f0567d43 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
@@ -44,6 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.c.multiprotocol.MultiprotocolCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
@@ -75,10 +75,14 @@ public class FSMTest {
                MockitoAnnotations.initMocks(this);
                final List<BgpParameters> tlvs = Lists.newArrayList();
 
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               this.ipv4tt.getAddressFamily()).setSafi(this.ipv4tt.getSubsequentAddressFamily()).build()));
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               this.linkstatett.getAddressFamily()).setSafi(this.linkstatett.getSubsequentAddressFamily()).build()));
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(this.ipv4tt.getAddressFamily()).setSafi(
+                                                               this.ipv4tt.getSubsequentAddressFamily()).build()).build()).build());
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(this.linkstatett.getAddressFamily()).setSafi(
+                                                               this.linkstatett.getSubsequentAddressFamily()).build()).build()).build());
                final BGPSessionPreferences prefs = new BGPSessionPreferences(30, (short) 3, null, tlvs);
                this.clientSession = new BGPSessionNegotiator(new HashedWheelTimer(), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE), this.speakerListener, prefs, new SimpleSessionListener());
                doAnswer(new Answer<Object>() {
@@ -98,8 +102,6 @@ public class FSMTest {
        }
 
        @Test
-       @Ignore
-       // FIXME BUG-100
        public void testAccSessionChar() throws InterruptedException {
                this.clientSession.channelActive(null);
                assertEquals(1, this.receivedMsgs.size());
@@ -109,20 +111,13 @@ public class FSMTest {
                assertTrue(this.receivedMsgs.get(1) instanceof Keepalive);
                this.clientSession.handleMessage(new KeepaliveBuilder().build());
                assertEquals(this.clientSession.getState(), BGPSessionNegotiator.State.Finished);
-               // Thread.sleep(3 * 1000);
-               // Thread.sleep(100);
-               // assertEquals(3, this.receivedMsgs.size());
-               // assertTrue(this.receivedMsgs.get(2) instanceof BGPKeepAliveMessage); // test of keepalive timer
-               // this.clientSession.handleMessage(new BGPOpenMessage(new ASNumber(30), (short) 3, null, null));
-               // assertEquals(4, this.receivedMsgs.size());
-               // assertTrue(this.receivedMsgs.get(3) instanceof BGPNotificationMessage);
-               // final BGPMessage m = this.clientListener.getListMsg().get(3);
-               // assertEquals(BGPError.FSM_ERROR, ((BGPNotificationMessage) m).getError());
+               Thread.sleep(1000);
+               Thread.sleep(100);
+               assertEquals(3, this.receivedMsgs.size());
+               assertTrue(this.receivedMsgs.get(2) instanceof Keepalive); // test of keepalive timer
        }
 
        @Test
-       @Ignore
-       // FIXME BUG-100
        public void testNotAccChars() throws InterruptedException {
                this.clientSession.channelActive(null);
                assertEquals(1, this.receivedMsgs.size());
@@ -148,19 +143,17 @@ public class FSMTest {
        }
 
        @Test
-       @Ignore
-       // FIXME BUG-100
        public void sendNotification() {
                this.clientSession.channelActive(null);
                this.clientSession.handleMessage(this.classicOpen);
                this.clientSession.handleMessage(new KeepaliveBuilder().build());
                assertEquals(this.clientSession.getState(), BGPSessionNegotiator.State.Finished);
-               try {
-                       this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).build());
-                       fail("Exception should be thrown.");
-               } catch (final IllegalStateException e) {
-                       assertEquals("Unexpected state Finished", e.getMessage());
-               }
+               this.clientSession.handleMessage(new OpenBuilder().setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).build());
+               assertEquals(3, this.receivedMsgs.size());
+               assertTrue(this.receivedMsgs.get(2) instanceof Notify);
+               final Notification m = this.receivedMsgs.get(2);
+               assertEquals(BGPError.FSM_ERROR.getCode(), ((Notify) m).getErrorCode().shortValue());
+               assertEquals(BGPError.FSM_ERROR.getSubcode(), ((Notify) m).getErrorSubcode().shortValue());
        }
 
        @After
index 038d91f1e980d3a560fb70792a2ec3b438d5e9ee..3f7c3969083a364b9b1807ca58f4f674d135970a 100644 (file)
@@ -16,10 +16,10 @@ import static org.junit.Assert.fail;
 import static org.junit.matchers.JUnitMatchers.containsString;
 
 import java.net.UnknownHostException;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
@@ -31,6 +31,7 @@ import org.opendaylight.protocol.framework.ProtocolMessageFactory;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.KeepaliveBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Notify;
@@ -39,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mess
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.ProtocolVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.BgpParametersBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.c.multiprotocol.MultiprotocolCapabilityBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
@@ -63,10 +65,19 @@ public class ParserTest {
                        (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
                        (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x17, (byte) 0x03, (byte) 0x02, (byte) 0x04, (byte) 0x04, (byte) 0x09 };
 
-       public static final byte[] openWithCpblt = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+       public static final byte[] openWithCpblt1 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
                        (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
-                       (byte) 0xff, (byte) 0x00, (byte) 0x1d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x64, (byte) 0x00, (byte) 0xb4,
-                       (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x14, (byte) 0x00 };
+                       (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+                       (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x40,
+                       (byte) 0x04, (byte) 0x00, (byte) 0x47 };
+
+       public static final byte[] openWithCpblt2 = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+                       (byte) 0xff, (byte) 0x00, (byte) 0x2d, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x48, (byte) 0x00, (byte) 0xb4,
+                       (byte) 0xac, (byte) 0x14, (byte) 0xa0, (byte) 0xaa, (byte) 0x10, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04,
+                       (byte) 0x40, (byte) 0x04, (byte) 0x00, (byte) 0x47, (byte) 0x02, (byte) 0x06, (byte) 0x01, (byte) 0x04, (byte) 0x00,
+                       (byte) 0x01, (byte) 0x00, (byte) 0x01 };
 
        final ProtocolMessageFactory<Notification> factory = new BGPMessageFactoryImpl();
 
@@ -255,8 +266,6 @@ public class ParserTest {
        }
 
        @Test
-       @Ignore
-       // FIXME BUG-100
        public void testTLVParser() throws UnknownHostException {
 
                final BGPTableType t1 = new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
@@ -264,10 +273,13 @@ public class ParserTest {
 
                final List<BgpParameters> tlvs = Lists.newArrayList();
 
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()));
-               tlvs.add((BgpParameters) new CMultiprotocolBuilder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(
-                               LinkstateAddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()));
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
+                                                               LinkstateSubsequentAddressFamily.class).build()).build()).build());
+               tlvs.add(new BgpParametersBuilder().setCParameters(
+                               new CMultiprotocolBuilder().setMultiprotocolCapability(
+                                               new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build());
 
                final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
                tableTypes.put(t1, true);
@@ -275,7 +287,9 @@ public class ParserTest {
                final Open open = new OpenBuilder().setMyAsNumber(72).setHoldTimer(180).setBgpIdentifier(new Ipv4Address("172.20.160.170")).setVersion(
                                new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
 
-               System.out.println(this.factory.put(open));
-               assertArrayEquals(openWithCpblt, this.factory.put(open));
+               final byte[] result = this.factory.put(open);
+
+               // the capabilities can be swapped.
+               assertTrue(Arrays.equals(openWithCpblt1, result) || Arrays.equals(openWithCpblt2, result));
        }
 }