Remove reliance on deprecated classes in BGP components
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionImpl.java
index 31c852268d2de51a45e09aec6895e6a95f4cfd46..032cea380d7856c8d2ff310f5fefacb9439e4c5e 100644 (file)
@@ -22,8 +22,8 @@ import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.protocol.bgp.parser.BGPError;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.parser.BGPTableType;
 import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
 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;
@@ -32,7 +32,9 @@ 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.Open;
 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.bgp.parameters.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -48,11 +50,14 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
 
        private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
 
+       /*
+        * 240
+        */
        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
+       private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE;
 
        /**
         * Internal session state.
@@ -77,6 +82,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        /**
         * System.nanoTime value about when was sent the last message Protected to be updated also in tests.
         */
+       @VisibleForTesting
        protected long lastMessageSentAt;
 
        /**
@@ -102,27 +108,30 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
 
        private final int keepAlive;
 
-       private final Set<BGPTableType> tableTypes;
+       private final Set<BgpTableType> tableTypes;
 
        BGPSessionImpl(final Timer timer, final BGPSessionListener listener, final Channel channel, final Open remoteOpen) {
                this.listener = Preconditions.checkNotNull(listener);
                this.stateTimer = Preconditions.checkNotNull(timer);
                this.channel = Preconditions.checkNotNull(channel);
                this.keepAlive = remoteOpen.getHoldTimer() / 3;
+               holdTimerValue = remoteOpen.getHoldTimer();
 
-               final Set<BGPTableType> tts = Sets.newHashSet();
+               final Set<TablesKey> tts = Sets.newHashSet();
+               final Set<BgpTableType> tats = Sets.newHashSet();
                if (remoteOpen.getBgpParameters() != null) {
                        for (final BgpParameters param : remoteOpen.getBgpParameters()) {
                                if (param instanceof CParameters) {
                                        final CParameters cp = (CParameters) param;
-                                       final BGPTableType tt = new BGPTableType(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
+                                       final TablesKey tt = new TablesKey(((CMultiprotocol) cp).getMultiprotocolCapability().getAfi(), ((CMultiprotocol) cp).getMultiprotocolCapability().getSafi());
                                        tts.add(tt);
+                                       tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
                                }
                        }
                }
 
                this.sync = new BGPSynchronization(this, this.listener, tts);
-               this.tableTypes = tts;
+               this.tableTypes = tats;
 
                if (remoteOpen.getHoldTimer() != 0) {
                        this.stateTimer.newTimeout(new TimerTask() {
@@ -233,7 +242,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
                }
 
                final long ct = System.nanoTime();
-               final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(HOLD_TIMER_VALUE);
+               final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(holdTimerValue);
 
                if (ct >= nextHold) {
                        logger.debug("HoldTimer expired. " + new Date());
@@ -275,7 +284,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        }
 
        @Override
-       final public String toString() {
+       public final String toString() {
                return addToStringAttributes(Objects.toStringHelper(this)).toString();
        }
 
@@ -286,7 +295,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
        }
 
        @Override
-       public Set<BGPTableType> getAdvertisedTableTypes() {
+       public Set<BgpTableType> getAdvertisedTableTypes() {
                return this.tableTypes;
        }