BUG-45 : migrated Keepalive message to generated source code. 88/1488/2
authorDana Kutenicsova <dkutenic@cisco.com>
Sun, 29 Sep 2013 17:13:13 +0000 (19:13 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Sun, 29 Sep 2013 20:43:20 +0000 (22:43 +0200)
Change-Id: I3a9d697bdb39eb85fa977f6711fd8253d5b213f1
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/message/BGPKeepAliveMessage.java [deleted file]
bgp/parser-api/src/main/yang/bgp-message.yang
bgp/parser-api/src/main/yang/bgp-multiprotocol.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/BGPMessageFactoryImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.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
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java

diff --git a/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/message/BGPKeepAliveMessage.java b/bgp/parser-api/src/main/java/org/opendaylight/protocol/bgp/parser/message/BGPKeepAliveMessage.java
deleted file mode 100644 (file)
index bf0370e..0000000
+++ /dev/null
@@ -1,25 +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.parser.message;
-
-import org.opendaylight.yangtools.yang.binding.Notification;
-
-/**
- * BGP KeepAlive message. Always empty.
- * 
- * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.4">BGP KeepAlive message</a>
- */
-public final class BGPKeepAliveMessage implements Notification {
-
-       /**
-        * Creates a BGP KeepAlive message.
-        */
-       public BGPKeepAliveMessage() {
-
-       }
-}
index fdb010dc49ef3a563768688f3084c671a6453034..1c3756c0404e13bff43c5cde2a016b5e21c9c3ac 100644 (file)
@@ -55,7 +55,7 @@ module bgp-message {
                        type inet:ipv4-address;
                        mandatory true;
                }
-               list optional-parameters {
+               list bgp-parameters {
                        reference "http://tools.ietf.org/html/rfc3392#section-4";
                        choice parameters {
                                container as4-bytes {
index e4e32f2ea313da54ee3da1cb39043b25f7eb7fbf..9aa6c55674655e2e6785841caac19df0ffa2b72d 100644 (file)
@@ -61,7 +61,7 @@ module bgp-multiprotocol {
                }
        }
 
-       augment "/bgp-msg:open/bgp-msg:optional-parameters/bgp-msg:parameters" {
+       augment "/bgp-msg:open/bgp-msg:bgp-parameters/bgp-msg:parameters" {
                case multiprotocol {
                        list capabilities {
                                container multiprotocol-capability {
index 43d583f8d66f435f5762faea83c73e697925ee35..5a706d8259abf379e3f15bcd06e0cf033557f189 100644 (file)
@@ -31,7 +31,6 @@ import org.opendaylight.protocol.bgp.linkstate.NetworkRouteState;
 import org.opendaylight.protocol.bgp.linkstate.RouteTag;
 import org.opendaylight.protocol.bgp.linkstate.RouterIdentifier;
 import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.bgp.parser.parameter.AS4BytesCapability;
@@ -45,6 +44,8 @@ import org.opendaylight.protocol.util.DefaultingTypesafeContainer;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 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.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.types.rev130919.BgpOrigin;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
@@ -164,8 +165,8 @@ public class APITest {
 
        @Test
        public void testBGPKeepAliveMessage() {
-               final Notification msg = new BGPKeepAliveMessage();
-               assertTrue(msg instanceof BGPKeepAliveMessage);
+               final Notification msg = new KeepaliveBuilder().build();
+               assertTrue(msg instanceof Keepalive);
        }
 
        @Test
index 2a1bbbdefef3c37197f5ebd46bf33446d9ada8a0..3a8cf312a203d27bf082145832b0027e94af55ac 100644 (file)
@@ -16,12 +16,13 @@ import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
 import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.util.ByteArray;
+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.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -97,7 +98,7 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
                        logger.debug("Received and parsed Notification Message: {}", msg);
                        break;
                case 4:
-                       msg = new BGPKeepAliveMessage();
+                       msg = new KeepaliveBuilder().build();
                        if (messageLength != COMMON_HEADER_LENGTH) {
                                throw new BGPDocumentedException("Message length field not within valid range.", BGPError.BAD_MSG_LENGTH, ByteArray.subByte(
                                                bs, 0, LENGTH_FIELD_LENGTH));
@@ -130,7 +131,7 @@ public final class BGPMessageFactoryImpl implements BGPMessageFactory {
                } else if (msg instanceof BGPNotificationMessage) {
                        msgType = 3;
                        msgBody = BGPNotificationMessageParser.put((BGPNotificationMessage) msg);
-               } else if (msg instanceof BGPKeepAliveMessage) {
+               } else if (msg instanceof Keepalive) {
                        msgType = 4;
                        msgBody = new byte[0];
                } else {
index 9a9139db5d1563ad3974a870b42b4578bcf07772..35255c7bd9614c0264dbdc08e6bd3ef4639601be 100644 (file)
@@ -25,11 +25,12 @@ import org.opendaylight.protocol.bgp.parser.BGPParameter;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
 import org.opendaylight.protocol.framework.AbstractProtocolSession;
+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.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,6 +48,8 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
 
        private static final int DEFAULT_HOLD_TIMER_VALUE = 15;
 
+       private static final Notification keepalive = new KeepaliveBuilder().build();
+
        public static int HOLD_TIMER_VALUE = DEFAULT_HOLD_TIMER_VALUE; // 240
 
        /**
@@ -163,7 +166,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                        logger.info("Session closed because Notification message received: {}", ((BGPNotificationMessage) msg).getError());
                        this.closeWithoutMessage();
                        this.listener.onSessionTerminated(this, new BGPTerminationReason(((BGPNotificationMessage) msg).getError()));
-               } else if (msg instanceof BGPKeepAliveMessage) {
+               } else if (msg instanceof Keepalive) {
                        // Keepalives are handled internally
                        logger.debug("Received KeepAlive messsage.");
                        this.kaCounter++;
@@ -254,7 +257,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                long nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
 
                if (ct >= nextKeepalive) {
-                       this.sendMessage(new BGPKeepAliveMessage());
+                       this.sendMessage(keepalive);
                        nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
                }
                this.stateTimer.newTimeout(new TimerTask() {
index 3ee9ef04c5e200560392ab186e72e0a2ea4549f4..e71121c13e0cd851c3c62e0efbf997ace2af8f10 100644 (file)
@@ -22,7 +22,6 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParameter;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.bgp.parser.parameter.CapabilityParameter;
@@ -31,6 +30,8 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.framework.AbstractSessionNegotiator;
 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.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -116,7 +117,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                case Idle:
                        throw new IllegalStateException("Unexpected state " + this.state);
                case OpenConfirm:
-                       if (msg instanceof BGPKeepAliveMessage) {
+                       if (msg instanceof Keepalive) {
                                negotiationSuccessful(this.session);
                        } else if (msg instanceof BGPNotificationMessage) {
                                final BGPNotificationMessage ntf = (BGPNotificationMessage) msg;
@@ -136,7 +137,7 @@ public final class BGPSessionNegotiator extends AbstractSessionNegotiator<Notifi
                                                                final MultiprotocolCapability cap = (MultiprotocolCapability) param;
                                                                if (LinkstateAddressFamily.class == cap.getAfi() && LinkstateSubsequentAddressFamily.class == cap.getSafi()) {
                                                                        this.remotePref = openObj;
-                                                                       this.channel.writeAndFlush(new BGPKeepAliveMessage());
+                                                                       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,
index 07552484132ee9860ba8e79e0d1566002a26d122..bbdd334dfb9f48904c939da43288df860d01acab 100644 (file)
@@ -35,7 +35,6 @@ import org.mockito.stubbing.Answer;
 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParameter;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
@@ -43,6 +42,8 @@ import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 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.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.yang.binding.Notification;
@@ -97,8 +98,8 @@ public class FSMTest {
                assertTrue(this.receivedMsgs.get(0) instanceof BGPOpenMessage);
                this.clientSession.handleMessage(this.classicOpen);
                assertEquals(2, this.receivedMsgs.size());
-               assertTrue(this.receivedMsgs.get(1) instanceof BGPKeepAliveMessage);
-               this.clientSession.handleMessage(new BGPKeepAliveMessage());
+               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);
@@ -140,7 +141,7 @@ public class FSMTest {
        public void sendNotification() {
                this.clientSession.channelActive(null);
                this.clientSession.handleMessage(this.classicOpen);
-               this.clientSession.handleMessage(new BGPKeepAliveMessage());
+               this.clientSession.handleMessage(new KeepaliveBuilder().build());
                assertEquals(this.clientSession.getState(), BGPSessionNegotiator.State.Finished);
                try {
                        this.clientSession.handleMessage(new BGPOpenMessage(new AsNumber((long) 30), (short) 3, null, null));
index cfd4c3c9e3f90953e3814b5903309d2e9db3ca8b..f6d403c0f91e96c7f443a48d857f5c33849e12f7 100644 (file)
@@ -26,7 +26,6 @@ import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPParameter;
 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPNotificationMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.bgp.parser.parameter.GracefulCapability;
@@ -38,6 +37,8 @@ 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.AsNumber;
 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.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.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.yang.binding.Notification;
@@ -95,13 +96,13 @@ public class ParserTest {
 
        @Test
        public void testKeepAliveMsg() throws DeserializerException, DocumentedException {
-               final Notification keepAlive = new BGPKeepAliveMessage();
+               final Notification keepAlive = new KeepaliveBuilder().build();
                final byte[] bytes = this.factory.put(keepAlive);
                assertArrayEquals(keepAliveBMsg, bytes);
 
                final Notification m = this.factory.parse(bytes).get(0);
 
-               assertTrue(m instanceof BGPKeepAliveMessage);
+               assertTrue(m instanceof Keepalive);
        }
 
        @Test
index c3a642b5a848f67f2e8681fd4f71c4995c8d0b5a..f30a814ea30561803eeeb74692873fe483b6d789 100644 (file)
@@ -16,10 +16,10 @@ import org.opendaylight.protocol.bgp.concepts.BGPTableType;
 import org.opendaylight.protocol.bgp.parser.BGPParameter;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.parser.message.BGPKeepAliveMessage;
 import org.opendaylight.protocol.bgp.parser.message.BGPOpenMessage;
 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
 import org.opendaylight.protocol.concepts.ListenerRegistration;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Keepalive;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
 import com.google.common.collect.Sets;
@@ -89,7 +89,7 @@ class EventBusRegistration implements ListenerRegistration<BGPSessionListener> {
                                        return tts;
                                }
                        });
-               } else if (message instanceof BGPKeepAliveMessage) {
+               } else if (message instanceof Keepalive) {
                        // do nothing
                } else {
                        listener.onMessage(null, message);