import com.google.common.base.Preconditions;
final class LinkstateAdjRIBsIn extends AbstractAdjRIBsIn<CLinkstateDestination, LinkstateRoute> {
- private static abstract class LinkstateRIBEntryData<LSATTR extends LinkStateAttribute> extends
- RIBEntryData<CLinkstateDestination, LinkstateRoute> {
- private final LSATTR lsattr;
+ private abstract static class LinkstateRIBEntryData<A extends LinkStateAttribute> extends
+ RIBEntryData<CLinkstateDestination, LinkstateRoute> {
+ private final A lsattr;
- protected LinkstateRIBEntryData(final PathAttributes attributes, final LSATTR lsattr) {
+ protected LinkstateRIBEntryData(final PathAttributes attributes, final A lsattr) {
super(attributes);
this.lsattr = Preconditions.checkNotNull(lsattr);
}
- protected abstract AttributeType createAttributes(LSATTR lsattr);
+ protected abstract AttributeType createAttributes(A lsattr);
protected abstract ObjectType createObject(CLinkstateDestination key);
// TODO: replace with actual values by IANA
public static final int TYPE = 99;
- private static final Logger logger = LoggerFactory.getLogger(LinkstateAttributeParser.class);
+ private static final Logger LOG = LoggerFactory.getLogger(LinkstateAttributeParser.class);
private static final int TYPE_LENGTH = 2;
private static boolean verifyLink(final Set<Integer> keys) {
for (final Integer i : keys) {
if (!LINK_TLVS.contains(i)) {
- logger.warn("Invalid link attribute {}", i);
+ LOG.warn("Invalid link attribute {}", i);
return false;
}
}
private static boolean verifyNode(final Set<Integer> keys) {
for (final Integer i : keys) {
if (!NODE_TLVS.contains(i)) {
- logger.warn("Invalid node attribute {}", i);
+ LOG.warn("Invalid node attribute {}", i);
return false;
}
}
private static boolean verifyPrefix(final Set<Integer> keys) {
for (final Integer i : keys) {
if (!PREFIX_TLVS.contains(i)) {
- logger.warn("Invalid prefix attribute {}", i);
+ LOG.warn("Invalid prefix attribute {}", i);
return false;
}
}
final LinkAttributesBuilder builder = new LinkAttributesBuilder();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.trace("Link attribute TLV {}", entry.getKey());
+ LOG.trace("Link attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
case 1028:
final Ipv4RouterIdentifier lipv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setLocalIpv4RouterId(lipv4);
- logger.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
+ LOG.debug("Parsed IPv4 Router-ID of local node: {}", lipv4);
break;
case 1029:
final Ipv6RouterIdentifier lipv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setLocalIpv6RouterId(lipv6);
- logger.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
+ LOG.debug("Parsed IPv6 Router-ID of local node: {}", lipv6);
break;
case 1030:
final Ipv4RouterIdentifier ripv4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setRemoteIpv4RouterId(ripv4);
- logger.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
+ LOG.debug("Parsed IPv4 Router-ID of remote node: {}", ripv4);
break;
case 1031:
final Ipv6RouterIdentifier ripv6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setRemoteIpv6RouterId(ripv6);
- logger.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
+ LOG.debug("Parsed IPv6 Router-ID of remote node: {}", ripv6);
break;
case 1088:
builder.setAdminGroup(new AdministrativeGroup(ByteArray.bytesToLong(value)));
- logger.debug("Parsed Administrative Group {}", builder.getAdminGroup());
+ LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case 1089:
builder.setMaxLinkBandwidth(new Bandwidth(value));
- logger.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
+ LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
break;
case 1090:
builder.setMaxReservableBandwidth(new Bandwidth(value));
- logger.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
+ LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
break;
case 1091:
int index = 0;
index += 4;
}
builder.setUnreservedBandwidth(unreservedBandwidth);
- logger.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
+ LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
break;
case 1092:
builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(value)));
- logger.debug("Parsed Metric {}", builder.getTeMetric());
+ LOG.debug("Parsed Metric {}", builder.getTeMetric());
break;
case 1093:
final LinkProtectionType lpt = LinkProtectionType.forValue(UnsignedBytes.toInt(value[0]));
throw new BGPParsingException("Link Protection Type not recognized: " + UnsignedBytes.toInt(value[0]));
}
builder.setLinkProtection(lpt);
- logger.debug("Parsed Link Protection Type {}", lpt);
+ LOG.debug("Parsed Link Protection Type {}", lpt);
break;
case 1094:
final boolean[] bits = ByteArray.parseBits(value[0]);
builder.setMplsProtocol(new MplsProtocolMask(bits[0], bits[1]));
- logger.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
+ LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
break;
case 1095:
builder.setMetric(new Metric(ByteArray.bytesToLong(value)));
- logger.debug("Parsed Metric {}", builder.getMetric());
+ LOG.debug("Parsed Metric {}", builder.getMetric());
break;
case 1096:
int i = 0;
i += 4;
}
builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
- logger.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
+ LOG.debug("Parsed Shared Risk Link Groups {}", Arrays.toString(sharedRiskLinkGroups.toArray()));
break;
case 1097:
final byte[] opaque = value;
- logger.debug("Parsed Opaque value : {}", Arrays.toString(opaque));
+ LOG.debug("Parsed Opaque value : {}", Arrays.toString(opaque));
break;
case 1098:
final String name = new String(value, Charsets.US_ASCII);
builder.setLinkName(name);
- logger.debug("Parsed Link Name : {}", name);
+ LOG.debug("Parsed Link Name : {}", name);
break;
default:
throw new BGPParsingException("Link Attribute not recognized, type: " + entry.getKey());
}
}
}
- logger.trace("Finished parsing Link Attributes.");
+ LOG.trace("Finished parsing Link Attributes.");
return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
}
final List<IsisAreaIdentifier> areaMembership = Lists.newArrayList();
final NodeAttributesBuilder builder = new NodeAttributesBuilder();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.trace("Node attribute TLV {}", entry.getKey());
+ LOG.trace("Node attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
switch (entry.getKey()) {
case 263:
while (i != value.length) {
final TopologyIdentifier topId = new TopologyIdentifier(ByteArray.bytesToInt(ByteArray.subByte(value, i, 2)) & 0x3fff);
topologyMembership.add(topId);
- logger.debug("Parsed Topology Identifier: {}", topId);
+ LOG.debug("Parsed Topology Identifier: {}", topId);
i += 2;
}
break;
case 1024:
final boolean[] flags = ByteArray.parseBits(value[0]);
builder.setNodeFlags(new NodeFlagBits(flags[0], flags[1], flags[2], flags[3]));
- logger.debug("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
+ LOG.debug("Parsed External bit {}, area border router {}.", flags[2], flags[3]);
break;
case 1025:
- logger.debug("Ignoring opaque value: {}.", Arrays.toString(value));
+ LOG.debug("Ignoring opaque value: {}.", Arrays.toString(value));
break;
case 1026:
builder.setDynamicHostname(new String(value, Charsets.US_ASCII));
- logger.debug("Parsed Node Name {}", builder.getDynamicHostname());
+ LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
break;
case 1027:
final byte[] dest = new byte[20];
System.arraycopy(value, 0, dest, 20 - value.length, value.length);
final IsisAreaIdentifier ai = new IsisAreaIdentifier(dest);
areaMembership.add(ai);
- logger.debug("Parsed AreaIdentifier {}", ai);
+ LOG.debug("Parsed AreaIdentifier {}", ai);
break;
case 1028:
final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForBytes(value));
builder.setIpv4RouterId(ip4);
- logger.debug("Parsed IPv4 Router Identifier {}", ip4);
+ LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
break;
case 1029:
final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForBytes(value));
builder.setIpv6RouterId(ip6);
- logger.debug("Parsed IPv6 Router Identifier {}", ip6);
+ LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
break;
default:
throw new BGPParsingException("Node Attribute not recognized, type: " + entry.getKey());
}
builder.setTopologyIdentifier(topologyMembership);
builder.setIsisAreaId(areaMembership);
- logger.trace("Finished parsing Node Attributes.");
+ LOG.trace("Finished parsing Node Attributes.");
return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
}
final List<RouteTag> routeTags = Lists.newArrayList();
final List<ExtendedRouteTag> exRouteTags = Lists.newArrayList();
for (final Entry<Integer, ByteList> entry : attributes.entrySet()) {
- logger.debug("Prefix attribute TLV {}", entry.getKey());
+ LOG.debug("Prefix attribute TLV {}", entry.getKey());
for (final byte[] value : entry.getValue().getBytes()) {
switch (entry.getKey()) {
case 1152:
final boolean[] flags = ByteArray.parseBits(value[0]);
final boolean upDownBit = flags[2];
builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).build());
- logger.trace("Parsed IGP flag (up/down bit) : {}", upDownBit);
+ LOG.trace("Parsed IGP flag (up/down bit) : {}", upDownBit);
break;
case 1153:
int offset = 0;
while (offset != value.length) {
final RouteTag routeTag = new RouteTag(ByteArray.subByte(value, offset, 4));
routeTags.add(routeTag);
- logger.trace("Parsed Route Tag: {}", routeTag);
+ LOG.trace("Parsed Route Tag: {}", routeTag);
offset += 4;
}
break;
while (offset != value.length) {
final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(value);
exRouteTags.add(exRouteTag);
- logger.trace("Parsed Extended Route Tag: {}", exRouteTag);
+ LOG.trace("Parsed Extended Route Tag: {}", exRouteTag);
offset += 4;
}
break;
case 1155:
final IgpMetric metric = new IgpMetric(ByteArray.bytesToLong(value));
builder.setPrefixMetric(metric);
- logger.trace("Parsed Metric: {}", metric);
+ LOG.trace("Parsed Metric: {}", metric);
break;
case 1156:
IpAddress fwdAddress = null;
fwdAddress = new IpAddress(Ipv6Util.addressForBytes(value));
break;
default:
- logger.debug("Ignoring unsupported forwarding address length {}", value.length);
+ LOG.debug("Ignoring unsupported forwarding address length {}", value.length);
}
- logger.trace("Parsed FWD Address: {}", fwdAddress);
+ LOG.trace("Parsed FWD Address: {}", fwdAddress);
break;
case 1157:
final byte[] opaque = value;
- logger.trace("Parsed Opaque value: {}", Arrays.toString(opaque));
+ LOG.trace("Parsed Opaque value: {}", Arrays.toString(opaque));
break;
default:
throw new BGPParsingException("Prefix Attribute not recognized, type: " + entry.getKey());
}
}
}
- logger.debug("Finished parsing Prefix Attributes.");
+ LOG.debug("Finished parsing Prefix Attributes.");
builder.setRouteTags(routeTags);
builder.setExtendedTags(exRouteTags);
return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build();
}
@Override
- public final void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
+ public void parseNlri(final byte[] nlri, final MpUnreachNlriBuilder builder) throws BGPParsingException {
if (nlri.length == 0) {
return;
}
public final class BGPOpenMessageParser implements MessageParser, MessageSerializer {
public static final int TYPE = 1;
- private static final Logger logger = LoggerFactory.getLogger(BGPOpenMessageParser.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPOpenMessageParser.class);
private static final int VERSION_SIZE = 1;
private static final int AS_SIZE = 2;
if (msg == null) {
throw new IllegalArgumentException("BGPOpen message cannot be null");
}
- logger.trace("Started serializing open message: {}", msg);
+ LOG.trace("Started serializing open message: {}", msg);
final Open open = (Open) msg;
final Map<byte[], Integer> optParams = Maps.newHashMap();
}
}
final byte[] ret = MessageUtil.formatMessage(TYPE, msgBody);
- logger.trace("Open message serialized to: {}", Arrays.toString(ret));
+ LOG.trace("Open message serialized to: {}", Arrays.toString(ret));
return ret;
}
if (body == null) {
throw new IllegalArgumentException("Byte array cannot be null.");
}
- logger.trace("Started parsing of open message: {}", Arrays.toString(body));
+ LOG.trace("Started parsing of open message: {}", Arrays.toString(body));
if (body.length < MIN_MSG_LENGTH) {
throw BGPDocumentedException.badMessageLength("Open message too small.", messageLength);
if (optLength > 0) {
fillParams(ByteArray.subByte(body, MIN_MSG_LENGTH, optLength), optParams);
}
- logger.trace("Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as, holdTime, bgpId, optParams);
+ LOG.trace("Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as, holdTime, bgpId, optParams);
return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer((int) holdTime).setBgpIdentifier(bgpId).setBgpParameters(
optParams).build();
}
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Byte array cannot be null or empty.");
}
- logger.trace("Started parsing of BGP parameter: {}", Arrays.toString(bytes));
+ LOG.trace("Started parsing of BGP parameter: {}", Arrays.toString(bytes));
int byteOffset = 0;
while (byteOffset < bytes.length) {
if (byteOffset + 2 >= bytes.length) {
if (param != null) {
params.add(param);
} else {
- logger.debug("Ignoring BGP Parameter type: {}", paramType);
+ LOG.debug("Ignoring BGP Parameter type: {}", paramType);
}
}
- logger.trace("Parsed BGP parameters: {}", Arrays.toString(params.toArray()));
+ LOG.trace("Parsed BGP parameters: {}", Arrays.toString(params.toArray()));
}
}
public class BGPUpdateMessageParser implements MessageParser {
public static final int TYPE = 2;
- private static Logger logger = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
+ private static Logger LOG = LoggerFactory.getLogger(BGPUpdateMessageParser.class);
/**
* Size of the withdrawn_routes_length field, in bytes.
if (body == null || body.length == 0) {
throw new IllegalArgumentException("Byte array cannot be null or empty.");
}
- logger.trace("Started parsing of update message: {}", Arrays.toString(body));
+ LOG.trace("Started parsing of update message: {}", Arrays.toString(body));
int byteOffset = 0;
throw e;
} catch (final Exception e) {
// Catch everything else and turn it into a BGPDocumentedException
- logger.warn("Could not parse BGP attributes", e);
+ LOG.warn("Could not parse BGP attributes", e);
throw new BGPDocumentedException("Could not parse BGP attributes.", BGPError.MALFORMED_ATTR_LIST, e);
}
}
if (nlri != null && !nlri.isEmpty()) {
eventBuilder.setNlri(new NlriBuilder().setNlri(nlri).build());
}
- logger.trace("Update message was parsed.");
+ LOG.trace("Update message was parsed.");
return eventBuilder.build();
}
}
public final class CapabilityParameterParser implements ParameterParser, ParameterSerializer {
public static final int TYPE = 2;
- private static final Logger logger = LoggerFactory.getLogger(CapabilityParameterParser.class);
+ private static final Logger LOG = LoggerFactory.getLogger(CapabilityParameterParser.class);
private final CapabilityRegistry reg;
public CapabilityParameterParser(final CapabilityRegistry reg) {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Byte array cannot be null or empty.");
}
- logger.trace("Started parsing of BGP Capability: {}", Arrays.toString(bytes));
+ LOG.trace("Started parsing of BGP Capability: {}", Arrays.toString(bytes));
int byteOffset = 0;
final int capCode = UnsignedBytes.toInt(bytes[byteOffset++]);
final int capLength = UnsignedBytes.toInt(bytes[byteOffset++]);
final CParameters ret = reg.parseCapability(capCode, paramBody);
if (ret == null) {
- logger.debug("Ignoring unsupported capability {}", capCode);
+ LOG.debug("Ignoring unsupported capability {}", capCode);
return null;
}
public byte[] serializeParameter(final BgpParameters parameter) {
final CParameters cap = parameter.getCParameters();
- logger.trace("Started serializing BGP Capability: {}", cap);
+ LOG.trace("Started serializing BGP Capability: {}", cap);
byte[] bytes = reg.serializeCapability(cap);
if (bytes == null) {
throw new IllegalArgumentException("Unhandled capability class" + cap.getImplementedInterface());
}
- logger.trace("BGP capability serialized to: {}", Arrays.toString(bytes));
+ LOG.trace("BGP capability serialized to: {}", Arrays.toString(bytes));
return ParameterUtil.formatParameter(TYPE, bytes);
}
protected static final short ROUTE_ORIGIN_SUBTYPE = 3;
+ private static final byte[] NO_EXPORT = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01 };
+
+ private static final byte[] NO_ADVERTISE = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x02 };
+
+ private static final byte[] NO_EXPORT_SUBCONFED = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x03 };
+
private CommunitiesParser() {
}
if (bytes.length != COMMUNITY_LENGTH) {
throw new BGPDocumentedException("Community with wrong length: " + bytes.length, BGPError.OPT_ATTR_ERROR);
}
- if (Arrays.equals(bytes, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x01 })) {
+ if (Arrays.equals(bytes, NO_EXPORT)) {
return CommunityUtil.NO_EXPORT;
- } else if (Arrays.equals(bytes, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x02 })) {
+ } else if (Arrays.equals(bytes, NO_ADVERTISE)) {
return CommunityUtil.NO_ADVERTISE;
- } else if (Arrays.equals(bytes, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x03 })) {
+ } else if (Arrays.equals(bytes, NO_EXPORT_SUBCONFED)) {
return CommunityUtil.NO_EXPORT_SUBCONFED;
}
return CommunityUtil.create((ByteArray.bytesToLong(Arrays.copyOfRange(bytes, 0, AS_NUMBER_LENGTH))),
protected abstract List<AutoCloseable> startImpl(BGPExtensionProviderContext context);
@Override
- public synchronized final void start(final BGPExtensionProviderContext context) {
+ public final synchronized void start(final BGPExtensionProviderContext context) {
Preconditions.checkState(this.registrations == null);
this.registrations = Preconditions.checkNotNull(startImpl(context));
}
@Override
- public synchronized final void stop() {
+ public final synchronized void stop() {
Preconditions.checkState(this.registrations != null);
for (final AutoCloseable r : this.registrations) {
import com.google.common.base.Preconditions;
-abstract class AbstractFamilyRegistry<CLASS, NUMBER> {
- private final Map<Class<? extends CLASS>, NUMBER> classToNumber = new ConcurrentHashMap<>();
- private final Map<NUMBER, Class<? extends CLASS>> numberToClass = new ConcurrentHashMap<>();
+abstract class AbstractFamilyRegistry<C, N> {
+ private final Map<Class<? extends C>, N> classToNumber = new ConcurrentHashMap<>();
+ private final Map<N, Class<? extends C>> numberToClass = new ConcurrentHashMap<>();
- protected synchronized AutoCloseable registerFamily(final Class<? extends CLASS> clazz, final NUMBER number) {
+ protected synchronized AutoCloseable registerFamily(final Class<? extends C> clazz, final N number) {
Preconditions.checkNotNull(clazz);
final Class<?> c = numberToClass.get(number);
Preconditions.checkState(c == null, "Number " + number + " already registered to " + c);
- final NUMBER n = classToNumber.get(clazz);
+ final N n = classToNumber.get(clazz);
Preconditions.checkState(n == null, "Class " + clazz + " already registered to " + n);
numberToClass.put(number, clazz);
};
}
- protected Class<? extends CLASS> classForFamily(final NUMBER number) {
+ protected Class<? extends C> classForFamily(final N number) {
return numberToClass.get(number);
}
- protected NUMBER numberForClass(final Class<? extends CLASS> clazz) {
+ protected N numberForClass(final Class<? extends C> clazz) {
return classToNumber.get(clazz);
}
}
import com.google.common.primitives.UnsignedBytes;
abstract class AbstractMessageRegistry implements MessageRegistry {
- private final static Logger logger = LoggerFactory.getLogger(AbstractMessageRegistry.class);
+ private static final Logger logger = LoggerFactory.getLogger(AbstractMessageRegistry.class);
+
+ private static final byte[] MARKER;
protected abstract Notification parseBody(final int type, final byte[] body, final int messageLength) throws BGPDocumentedException;
protected abstract byte[] serializeMessageImpl(final Notification message);
- private final static byte[] MARKER;
-
static {
MARKER = new byte[MessageUtil.MARKER_LENGTH];
Arrays.fill(MARKER, (byte) 0xff);
*
*/
final class BGPByteToMessageDecoder extends ByteToMessageDecoder {
- private final static Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPByteToMessageDecoder.class);
private final MessageRegistry registry;
public BGPByteToMessageDecoder(final MessageRegistry registry) {
*/
@Sharable
final class BGPMessageToByteEncoder extends MessageToByteEncoder<Notification> {
- private final static Logger LOG = LoggerFactory.getLogger(BGPMessageToByteEncoder.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPMessageToByteEncoder.class);
private final MessageRegistry registry;
BGPMessageToByteEncoder(final MessageRegistry registry) {
* RIB actions.
*/
public final class BGPPeer implements BGPSessionListener, Peer {
- private static final Logger logger = LoggerFactory.getLogger(BGPPeer.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPPeer.class);
private final Set<TablesKey> tables = Sets.newHashSet();
private final String name;
private final RIBImpl rib;
if (message instanceof Update) {
this.rib.updateTables(this, (Update) message);
} else {
- logger.info("Ignoring unhandled message class " + message.getClass());
+ LOG.info("Ignoring unhandled message class " + message.getClass());
}
}
@Override
public void onSessionUp(final BGPSession session) {
- logger.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
+ LOG.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
for (final BgpTableType t : session.getAdvertisedTableTypes()) {
this.tables.add(new TablesKey(t.getAfi(), t.getSafi()));
@Override
public void onSessionDown(final BGPSession session, final Exception e) {
- logger.info("Session with peer {} went down", this.name, e);
+ LOG.info("Session with peer {} went down", this.name, e);
cleanup();
}
@Override
public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
- logger.info("Session with peer {} terminated: {}", this.name, cause);
+ LOG.info("Session with peer {} terminated: {}", this.name, cause);
cleanup();
}
@Override
- public final String toString() {
+ public String toString() {
return addToStringAttributes(Objects.toStringHelper(this)).toString();
}
@VisibleForTesting
public class BGPSessionImpl extends AbstractProtocolSession<Notification> implements BGPSession {
- private static final Logger logger = LoggerFactory.getLogger(BGPSessionImpl.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPSessionImpl.class);
/*
* 240
*/
private static final int DEFAULT_HOLD_TIMER_VALUE = 15;
- private static final Notification keepalive = new KeepaliveBuilder().build();
+ private static final Notification KEEP_ALIVE = new KeepaliveBuilder().build();
private static int holdTimerValue = DEFAULT_HOLD_TIMER_VALUE;
@Override
public synchronized void close() {
- logger.debug("Closing session: {}", this);
+ LOG.debug("Closing session: {}", this);
if (this.state != State.Idle) {
this.sendMessage(new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build());
this.channel.close();
this.terminate(BGPError.FSM_ERROR);
} else if (msg instanceof Notify) {
// Notifications are handled internally
- logger.info("Session closed because Notification message received: {} / {}", ((Notify) msg).getErrorCode(),
+ LOG.info("Session closed because Notification message received: {} / {}", ((Notify) msg).getErrorCode(),
((Notify) msg).getErrorSubcode());
this.closeWithoutMessage();
this.listener.onSessionTerminated(this,
new BGPTerminationReason(BGPError.forValue(((Notify) msg).getErrorCode(), ((Notify) msg).getErrorSubcode())));
} else if (msg instanceof Keepalive) {
// Keepalives are handled internally
- logger.debug("Received KeepAlive messsage.");
+ LOG.debug("Received KeepAlive messsage.");
this.kaCounter++;
if (this.kaCounter >= 2) {
this.sync.kaReceived();
try {
this.channel.writeAndFlush(msg);
this.lastMessageSentAt = System.nanoTime();
- logger.debug("Sent message: {}", msg);
+ LOG.debug("Sent message: {}", msg);
} catch (final Exception e) {
- logger.warn("Message {} was not sent.", msg, e);
+ LOG.warn("Message {} was not sent.", msg, e);
}
}
private synchronized void closeWithoutMessage() {
- logger.debug("Closing session: {}", this);
+ LOG.debug("Closing session: {}", this);
this.channel.close();
this.state = State.Idle;
}
final long nextHold = this.lastMessageReceivedAt + TimeUnit.SECONDS.toNanos(holdTimerValue);
if (ct >= nextHold) {
- logger.debug("HoldTimer expired. " + new Date());
+ LOG.debug("HoldTimer expired. " + new Date());
this.terminate(BGPError.HOLD_TIMER_EXPIRED);
} else {
this.stateTimer.newTimeout(new TimerTask() {
long nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
if (ct >= nextKeepalive) {
- this.sendMessage(keepalive);
+ this.sendMessage(KEEP_ALIVE);
nextKeepalive = this.lastMessageSentAt + TimeUnit.SECONDS.toNanos(this.keepAlive);
}
this.stateTimer.newTimeout(new TimerTask() {
Finished,
}
- private static final Logger logger = LoggerFactory.getLogger(BGPSessionNegotiator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPSessionNegotiator.class);
private final BGPSessionListener listener;
private final Timer timer;
private final BGPSessionPreferences localPref;
@Override
protected synchronized void handleMessage(final Notification msg) {
- logger.debug("Channel {} handling message in state {}", this.channel, this.state);
+ LOG.debug("Channel {} handling message in state {}", this.channel, this.state);
switch (this.state) {
case Finished:
}
// Catch-all for unexpected message
- logger.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
+ LOG.warn("Channel {} state {} unexpected message {}", this.channel, this.state, msg);
this.channel.writeAndFlush(new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
BGPError.FSM_ERROR.getSubcode()).build());
negotiationFailed(new BGPDocumentedException("Unexpected message", BGPError.FSM_ERROR));
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);
+ LOG.debug("Channel {} moved to OpenConfirm state with remote proposal {}", this.channel, this.remotePref);
return;
}
}
*/
public class BGPSynchronization {
- private static final Logger logger = LoggerFactory.getLogger(BGPSynchronization.class);
+ private static final Logger LOG = LoggerFactory.getLogger(BGPSynchronization.class);
private static class SyncVariables {
}
final SyncVariables s = this.syncStorage.get(type);
if (s == null) {
- logger.warn("BGPTableType was not present in open message : {}", type);
+ LOG.warn("BGPTableType was not present in open message : {}", type);
return;
}
s.setUpd(true);
if (!s.getUpd()) {
s.setEorTrue();
final Update up = generateEOR(entry.getKey());
- logger.debug("Sending synchronization message: {}", up);
+ LOG.debug("Sending synchronization message: {}", up);
this.listener.onMessage(this.session, up);
}
s.setUpd(false);
*/
package org.opendaylight.protocol.bgp.rib.impl.spi;
-
/**
* Interface that provides the initial acceptable session characteristics with which the session should be started.
*/
* @param address serves as constraint, the implementation can also take time into consideration
* @return BGPSessionPreferences with acceptable session characteristics
*/
- public BGPSessionPreferences getProposal();
+ BGPSessionPreferences getProposal();
}
@ThreadSafe
public abstract class AbstractAdjRIBsIn<I, D extends DataObject> implements AdjRIBsIn {
- protected static abstract class RIBEntryData<I, D extends DataObject> {
+ protected abstract static class RIBEntryData<I, D extends DataObject> {
private final PathAttributes attributes;
protected RIBEntryData(final PathAttributes attributes) {
}
private void electCandidate(final DataModificationTransaction transaction, final RIBEntryData<I, D> candidate) {
- LOG.trace("Electing state {} to supersede {}", candidate, currentState);
+ LOG.trace("Electing state {} to supersede {}", candidate, this.currentState);
if (this.currentState == null || !this.currentState.equals(candidate)) {
transaction.putOperationalData(getName(), candidate.getDataObject(this.key));
if (candidate != null) {
electCandidate(transaction, candidate);
} else {
- LOG.trace("Final candidate disappeared, removing entry {}", name);
+ LOG.trace("Final candidate disappeared, removing entry {}", this.name);
transaction.removeOperationalData(this.name);
}
- return candidates.isEmpty();
+ return this.candidates.isEmpty();
}
synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData<I, D> state) {
this.comparator = Preconditions.checkNotNull(comparator);
this.basePath = InstanceIdentifier.builder(LocRib.class).child(Tables.class, key).toInstance();
- eor = new UpdateBuilder().setPathAttributes(
+ this.eor = new UpdateBuilder().setPathAttributes(
new PathAttributesBuilder().addAugmentation(
PathAttributes1.class,
new PathAttributes1Builder().setMpReachNlri(
new MpReachNlriBuilder().setAfi(key.getAfi()).setSafi(key.getSafi()).build()).build()).build()).build();
- trans.putOperationalData(basePath, new TablesBuilder().setAfi(key.getAfi()).setSafi(key.getSafi()).setUptodate(Boolean.FALSE).build());
+ trans.putOperationalData(this.basePath,
+ new TablesBuilder().setAfi(key.getAfi()).setSafi(key.getSafi()).setUptodate(Boolean.FALSE).build());
}
private void setUptodate(final DataModificationTransaction trans, final Boolean uptodate) {
- final Tables t = (Tables) trans.readOperationalData(basePath);
+ final Tables t = (Tables) trans.readOperationalData(this.basePath);
if (t == null || !uptodate.equals(t.isUptodate())) {
LOG.debug("Table {} switching uptodate to {}", uptodate);
- trans.putOperationalData(basePath, new TablesBuilder(t).setUptodate(uptodate).build());
+ trans.putOperationalData(this.basePath, new TablesBuilder(t).setUptodate(uptodate).build());
}
}
}
}
- peers.remove(peer);
- setUptodate(trans, peers.values().contains(Boolean.FALSE) == false);
+ this.peers.remove(peer);
+ setUptodate(trans, !this.peers.values().contains(Boolean.FALSE));
}
protected abstract InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<Tables> basePath, final I id);
}
e.setState(trans, peer, data);
- if (!peers.containsKey(peer)) {
- peers.put(peer, Boolean.FALSE);
+ if (!this.peers.containsKey(peer)) {
+ this.peers.put(peer, Boolean.FALSE);
setUptodate(trans, Boolean.FALSE);
}
}
@Override
public final void markUptodate(final DataModificationTransaction trans, final Peer peer) {
- peers.put(peer, Boolean.TRUE);
- setUptodate(trans, peers.values().contains(Boolean.FALSE) == false);
+ this.peers.put(peer, Boolean.TRUE);
+ setUptodate(trans, !this.peers.values().contains(Boolean.FALSE));
}
@Override
public final Update endOfRib() {
- return eor;
+ return this.eor;
}
}
protected abstract List<AutoCloseable> startRIBExtensionProviderImpl(RIBExtensionProviderContext context);
@Override
- public synchronized final void startRIBExtensionProvider(final RIBExtensionProviderContext context) {
+ public final synchronized void startRIBExtensionProvider(final RIBExtensionProviderContext context) {
Preconditions.checkState(this.registrations == null);
this.registrations = Preconditions.checkNotNull(startRIBExtensionProviderImpl(context));
}
@Override
- public synchronized final void stopRIBExtensionProvider() {
+ public final synchronized void stopRIBExtensionProvider() {
Preconditions.checkState(this.registrations != null);
for (final AutoCloseable r : this.registrations) {
*/
public class Main {
- private static final Logger logger = LoggerFactory.getLogger(Main.class);
+ private static final Logger LOG = LoggerFactory.getLogger(Main.class);
private static String usage = "DESCRIPTION:\n"
+ "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
as = new AsNumber(Long.valueOf(args[i + 1]));
i++;
} else {
- logger.error("WARNING: Unrecognized argument: " + args[i]);
+ LOG.error("WARNING: Unrecognized argument: " + args[i]);
}
i++;
}
final BGPSessionPreferences proposal = prop.getProposal();
- logger.debug("{} {} {}", address, sessionListener, proposal);
+ LOG.debug("{} {} {}", address, sessionListener, proposal);
final InetSocketAddress addr = address;
m.dispatcher.createClient(addr, proposal, sessionListener,
* Testing BGP Listener.
*/
public class TestingListener implements BGPSessionListener {
- private static final Logger logger = LoggerFactory.getLogger(TestingListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
@Override
public void onMessage(final BGPSession session, final Notification message) {
- logger.info("Client Listener: message received: {}", message.toString());
+ LOG.info("Client Listener: message received: {}", message.toString());
}
@Override
public void onSessionUp(final BGPSession session) {
- logger.info("Client Listener: Session Up.");
+ LOG.info("Client Listener: Session Up.");
}
@Override
public void onSessionDown(final BGPSession session, final Exception e) {
- logger.info("Client Listener: Connection lost.");
+ LOG.info("Client Listener: Connection lost.");
session.close();
}
@Override
public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
- logger.info("Client Listener: Connection lost: {}.", cause);
+ LOG.info("Client Listener: Connection lost: {}.", cause);
}
}