import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.SimpleChannelInboundHandler;
import java.io.IOException;
import java.util.Date;
+import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
import org.opendaylight.protocol.bgp.parser.AsNumberUtil;
import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BgpExtendedMessageUtil;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.optional.capabilities.c.parameters.MultiprotocolCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.AddPathCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapability;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
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;
private static final int KA_TO_DEADTIMER_RATIO = 3;
+ private static final String EXTENDED_MSG_DECODER = "EXTENDED_MSG_DECODER";
+
static final String END_OF_INPUT = "End of input detected. Close the session.";
/**
private State state = State.OPEN_CONFIRM;
private final Set<BgpTableType> tableTypes;
+ private final List<AddressFamilies> addPathTypes;
private final int holdTimerValue;
private final int keepAlive;
private final AsNumber asNumber;
public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen, final BGPSessionPreferences localPreferences,
final BGPPeerRegistry peerRegistry) {
this(listener, channel, remoteOpen, localPreferences.getHoldTime(), peerRegistry);
- this.sessionStats = new BGPSessionStats(remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.of(localPreferences), this.tableTypes);
+ this.sessionStats = new BGPSessionStats(remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.of(localPreferences), this.tableTypes, this.addPathTypes);
}
public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen, final int localHoldTimer,
this.keepAlive = this.holdTimerValue / KA_TO_DEADTIMER_RATIO;
this.asNumber = AsNumberUtil.advertizedAsNumber(remoteOpen);
this.peerRegistry = peerRegistry;
+ final boolean enableExMess = BgpExtendedMessageUtil.advertizedBgpExtendedMessageCapability(remoteOpen);
+ if (enableExMess) {
+ this.channel.pipeline().replace(BGPMessageHeaderDecoder.class, EXTENDED_MSG_DECODER, BGPMessageHeaderDecoder.getExtendedBGPMessageHeaderDecoder());
+ }
final Set<TablesKey> tts = Sets.newHashSet();
final Set<BgpTableType> tats = Sets.newHashSet();
+ final List<AddressFamilies> addPathCapabilitiesList = Lists.newArrayList();
if (remoteOpen.getBgpParameters() != null) {
for (final BgpParameters param : remoteOpen.getBgpParameters()) {
for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) {
final CParameters cParam = optCapa.getCParameters();
- if ( cParam.getAugmentation(CParameters1.class) == null ||
- cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() == null ) {
+ if ( cParam.getAugmentation(CParameters1.class) == null) {
continue;
}
- final MultiprotocolCapability multi = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
- final TablesKey tt = new TablesKey(multi.getAfi(), multi.getSafi());
- LOG.trace("Added table type to sync {}", tt);
- tts.add(tt);
- tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
+ if(cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
+ final MultiprotocolCapability multi = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
+ final TablesKey tt = new TablesKey(multi.getAfi(), multi.getSafi());
+ LOG.trace("Added table type to sync {}", tt);
+ tts.add(tt);
+ tats.add(new BgpTableTypeImpl(tt.getAfi(), tt.getSafi()));
+ } else if (cParam.getAugmentation(CParameters1.class).getAddPathCapability() != null) {
+ final AddPathCapability addPathCap = cParam.getAugmentation(CParameters1.class).getAddPathCapability();
+ addPathCapabilitiesList.addAll(addPathCap.getAddressFamilies());
+ }
}
}
}
this.sync = new BGPSynchronization(this.listener, tts);
this.tableTypes = tats;
+ this.addPathTypes = addPathCapabilitiesList;
if (this.holdTimerValue != 0) {
channel.eventLoop().schedule(new Runnable() {
}
this.bgpId = remoteOpen.getBgpIdentifier();
this.sessionStats = new BGPSessionStats(remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.<BGPSessionPreferences>absent(),
- this.tableTypes);
+ this.tableTypes, this.addPathTypes);
}
@Override
public synchronized void close() {
if (this.state != State.IDLE && this.channel.isActive()) {
this.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).setErrorSubcode(
- BGPError.CEASE.getSubcode()).build());
+ BGPError.CEASE.getSubcode()).build());
}
this.closeWithoutMessage();
}
} else if (msg instanceof Notify) {
// Notifications are handled internally
LOG.info("Session closed because Notification message received: {} / {}", ((Notify) msg).getErrorCode(),
- ((Notify) msg).getErrorSubcode());
+ ((Notify) msg).getErrorSubcode());
this.closeWithoutMessage();
this.listener.onSessionTerminated(this, new BGPTerminationReason(BGPError.forValue(((Notify) msg).getErrorCode(),
- ((Notify) msg).getErrorSubcode())));
+ ((Notify) msg).getErrorSubcode())));
this.sessionStats.updateReceivedMsgErr((Notify) msg);
} else if (msg instanceof Keepalive) {
// Keepalives are handled internally
if (this.kaCounter >= 2) {
this.sync.kaReceived();
}
- } else {
- // All others are passed up
+ } else if (msg instanceof RouteRefresh) {
+ this.listener.onMessage(this, msg);
+ this.sessionStats.updateReceivedMsgRR();
+ } else if (msg instanceof Update) {
this.listener.onMessage(this, msg);
this.sync.updReceived((Update) msg);
this.sessionStats.updateReceivedMsgUpd();
+ } else {
+ LOG.warn("Ignoring unhandled message: {}.", msg.getClass());
}
}
@GuardedBy("this")
private void writeEpilogue(final ChannelFuture future, final Notification msg) {
future.addListener(
- new ChannelFutureListener() {
- @Override
- public void operationComplete(final ChannelFuture f) {
- if (!f.isSuccess()) {
- LOG.warn("Failed to send message {} to socket {}", msg, f.cause(), BGPSessionImpl.this.channel);
- } else {
- LOG.trace("Message {} sent to socket {}", msg, BGPSessionImpl.this.channel);
+ new ChannelFutureListener() {
+ @Override
+ public void operationComplete(final ChannelFuture f) {
+ if (!f.isSuccess()) {
+ LOG.warn("Failed to send message {} to socket {}", msg, f.cause(), BGPSessionImpl.this.channel);
+ } else {
+ LOG.trace("Message {} sent to socket {}", msg, BGPSessionImpl.this.channel);
+ }
}
- }
- });
+ });
this.lastMessageSentAt = System.nanoTime();
this.sessionStats.updateSentMsgTotal();
if (msg instanceof Update) {
return this.tableTypes;
}
+ @Override
+ public List<AddressFamilies> getAdvertisedAddPathTableTypes() {
+ return this.addPathTypes;
+ }
+
protected synchronized void sessionUp() {
this.sessionStats.startSessionStopwatch();
this.state = State.UP;