final int length = ByteArray.bytesToInt(ByteArray.subByte(bytes, byteOffset, LENGTH_SIZE));
byteOffset += LENGTH_SIZE;
final byte[] value = ByteArray.subByte(bytes, byteOffset, length);
- ByteList values = map.containsKey(type) ? values = map.get(type) : new ByteList();
+ final ByteList values = map.containsKey(type) ? map.get(type) : new ByteList();
values.add(value);
map.put(type, values);
byteOffset += length;
* @param error specific documented error
* @param cause cause for the error
*/
- public BGPDocumentedException(final String message, final BGPError error, final Throwable cause) {
+ public BGPDocumentedException(final String message, final BGPError error, final Exception cause) {
this(message, error, null, cause);
}
* @param data data associated with the error
* @param cause cause for the error
*/
- public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Throwable cause) {
- super(message);
+ public BGPDocumentedException(final String message, final BGPError error, final byte[] data, final Exception cause) {
+ super(message, cause);
this.error = error;
this.data = data;
logger.error("Error = " + error, this);
public static BGPDocumentedException badMessageLength(final String message, final int length) {
Preconditions.checkArgument(length >= 0 && length <= 65535);
- return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] {
- UnsignedBytes.checkedCast(length / 256), UnsignedBytes.checkedCast(length % 256) });
+ return new BGPDocumentedException(message, BGPError.BAD_MSG_LENGTH, new byte[] { UnsignedBytes.checkedCast(length / 256),
+ UnsignedBytes.checkedCast(length % 256) });
}
}
public static BGPError forValue(final int e, final int s) {
if (e == 1) {
- if (s == 1)
+ if (s == 1) {
return BGPError.CONNECTION_NOT_SYNC;
- if (s == 2)
+ }
+ if (s == 2) {
return BGPError.BAD_MSG_LENGTH;
- if (s == 3)
+ }
+ if (s == 3) {
return BGPError.BAD_MSG_TYPE;
+ }
} else if (e == 2) {
- if (s == 0)
+ if (s == 0) {
return BGPError.UNSPECIFIC_OPEN_ERROR;
- if (s == 1)
+ }
+ if (s == 1) {
return BGPError.VERSION_NOT_SUPPORTED;
- if (s == 2)
+ }
+ if (s == 2) {
return BGPError.BAD_PEER_AS;
- if (s == 3)
+ }
+ if (s == 3) {
return BGPError.BAD_BGP_ID;
- if (s == 4)
+ }
+ if (s == 4) {
return BGPError.OPT_PARAM_NOT_SUPPORTED;
- if (s == 6)
+ }
+ if (s == 6) {
return BGPError.HOLD_TIME_NOT_ACC;
+ }
} else if (e == 3) {
- if (s == 1)
+ if (s == 1) {
return BGPError.MALFORMED_ATTR_LIST;
- if (s == 2)
+ }
+ if (s == 2) {
return BGPError.WELL_KNOWN_ATTR_NOT_RECOGNIZED;
- if (s == 3)
+ }
+ if (s == 3) {
return BGPError.WELL_KNOWN_ATTR_MISSING;
- if (s == 4)
+ }
+ if (s == 4) {
return BGPError.ATTR_FLAGS_MISSING;
- if (s == 5)
+ }
+ if (s == 5) {
return BGPError.ATTR_LENGTH_ERROR;
- if (s == 6)
+ }
+ if (s == 6) {
return BGPError.ORIGIN_ATTR_NOT_VALID;
- if (s == 8)
+ }
+ if (s == 8) {
return BGPError.NEXT_HOP_NOT_VALID;
- if (s == 9)
+ }
+ if (s == 9) {
return BGPError.OPT_ATTR_ERROR;
- if (s == 10)
+ }
+ if (s == 10) {
return BGPError.NETWORK_NOT_VALID;
- if (s == 11)
+ }
+ if (s == 11) {
return BGPError.AS_PATH_MALFORMED;
- } else if (e == 4)
+ }
+ } else if (e == 4) {
return BGPError.HOLD_TIMER_EXPIRED;
- else if (e == 5)
+ } else if (e == 5) {
return BGPError.FSM_ERROR;
- else if (e == 6)
+ } else if (e == 6) {
return BGPError.CEASE;
+ }
throw new IllegalArgumentException("BGP Error code " + e + " and subcode " + s + " not recognized.");
}
}
@Override
public boolean equals(final Object obj) {
- if (obj != null && obj instanceof BgpTableTypeImpl) {
+ if (obj instanceof BgpTableTypeImpl) {
final BgpTableTypeImpl o = (BgpTableTypeImpl) obj;
return this.afi.equals(o.afi) && this.safi.equals(o.safi);
}
@Override
public synchronized void start(final BGPExtensionProviderContext context) {
- Preconditions.checkState(registrations == null);
+ Preconditions.checkState(this.registrations == null);
final List<AutoCloseable> regs = new ArrayList<>();
final AddressFamilyRegistry afiReg = context.getAddressFamilyRegistry();
regs.add(context.registerSubsequentAddressFamily(MplsLabeledVpnSubsequentAddressFamily.class, 128));
final NlriRegistry nlriReg = context.getNlriRegistry();
- regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new Ipv4NlriParser()));
- regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class,
- new Ipv6NlriParser()));
+ regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv4NlriParser()));
+ regs.add(context.registerNlriParser(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, new Ipv6NlriParser()));
final AttributeRegistry attrReg = context.getAttributeRegistry();
regs.add(context.registerAttributeParser(OriginAttributeParser.TYPE, new OriginAttributeParser()));
regs.add(context.registerAttributeParser(AsPathAttributeParser.TYPE, new AsPathAttributeParser()));
regs.add(context.registerAttributeParser(NextHopAttributeParser.TYPE, new NextHopAttributeParser()));
- regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE,
- new MultiExitDiscriminatorAttributeParser()));
+ regs.add(context.registerAttributeParser(MultiExitDiscriminatorAttributeParser.TYPE, new MultiExitDiscriminatorAttributeParser()));
regs.add(context.registerAttributeParser(LocalPreferenceAttributeParser.TYPE, new LocalPreferenceAttributeParser()));
regs.add(context.registerAttributeParser(AtomicAggregateAttributeParser.TYPE, new AtomicAggregateAttributeParser()));
regs.add(context.registerAttributeParser(AggregatorAttributeParser.TYPE, new AggregatorAttributeParser()));
final BGPUpdateMessageParser ump = new BGPUpdateMessageParser(attrReg);
regs.add(context.registerMessageParser(BGPUpdateMessageParser.TYPE, ump));
// Serialization of Update message is not supported
- // regs.add(msgReg.registerMessageSerializer(Update.class, ump));
final BGPNotificationMessageParser nmp = new BGPNotificationMessageParser();
regs.add(context.registerMessageParser(BGPNotificationMessageParser.TYPE, nmp));
regs.add(context.registerMessageParser(BGPKeepAliveMessageParser.TYPE, kamp));
regs.add(context.registerMessageSerializer(Keepalive.class, kamp));
- registrations = regs;
+ this.registrations = regs;
}
@Override
public synchronized void stop() {
- Preconditions.checkState(registrations != null);
+ Preconditions.checkState(this.registrations != null);
- for (AutoCloseable r : registrations) {
+ for (final AutoCloseable r : this.registrations) {
try {
r.close();
- } catch (Exception e) {
+ } catch (final Exception e) {
logger.warn("Failed to close registration", e);
}
}
- registrations = null;
+ this.registrations = null;
}
}
final byte[] bytes = null;
// final GracefulCapability param = (GracefulCapability) capability;
- // final byte[] bytes = new byte[(RESTART_FLAGS_SIZE + TIMER_SIZE + (AFI_SIZE * Byte.SIZE + SAFI_SIZE * Byte.SIZE +
+ // 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())
* the collection is a Set.
*
*/
-public class AsPathSegmentParser {
+public final class AsPathSegmentParser {
public static final int TYPE_LENGTH = 1; // bytes
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
import org.opendaylight.protocol.bgp.parser.BGPError;
-import org.opendaylight.protocol.bgp.parser.impl.CommunityUtil;
import org.opendaylight.protocol.concepts.Ipv4Util;
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
/**
* Parser for Extended Communities Path Attribute.
*/
-public class CommunitiesParser {
+public final class CommunitiesParser {
public static final int EXTENDED_COMMUNITY_LENGTH = 8; // bytes
return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else if (subType == 3) {
return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else {
return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
new AsSpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
}
case 40: // 01000000
return new CAsSpecificExtendedCommunityBuilder().setAsSpecificExtendedCommunity(
new AsSpecificExtendedCommunityBuilder().setTransitive(true).setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
case 2:
if (subType == 2) {
return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else if (subType == 3) {
return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else {
throw new BGPDocumentedException("Could not parse Extended Community subtype: " + subType, BGPError.OPT_ATTR_ERROR);
}
return new CRouteTargetExtendedCommunityBuilder().setRouteTargetExtendedCommunity(
new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else if (subType == 3) {
return new CRouteOriginExtendedCommunityBuilder().setRouteOriginExtendedCommunity(
new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(
new AsNumber(ByteArray.bytesToLong(ByteArray.subByte(value, 0, AS_NUMBER_LENGTH)))).setLocalAdministrator(
- ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
+ ByteArray.subByte(value, AS_NUMBER_LENGTH, AS_LOCAL_ADMIN_LENGTH)).build()).build();
} else {
return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
new Inet4SpecificExtendedCommunityBuilder().setTransitive(false).setGlobalAdministrator(
Ipv4Util.addressForBytes(ByteArray.subByte(value, 0, 4))).setLocalAdministrator(
- ByteArray.subByte(value, 4, 2)).build()).build();
+ ByteArray.subByte(value, 4, 2)).build()).build();
}
case 41: // 01000001
return new CInet4SpecificExtendedCommunityBuilder().setInet4SpecificExtendedCommunity(
* 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.impl;
+package org.opendaylight.protocol.bgp.parser.impl.message.update;
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.message.rev130918.path.attributes.CommunitiesBuilder;
*/
public static final Community NO_EXPORT_SUBCONFED = CommunityUtil.create(0xFFFF, 0xFF03);
+ private CommunityUtil() {
+
+ }
+
/**
* Creates a new Community given AS number value and semantics using generated CommunitiesBuilder.
*
import org.junit.Test;
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPUpdateMessageParser;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.junit.Ignore;
import org.junit.Test;
+import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
public class CommunityTest {
public interface NlriRegistry {
public MpUnreachNlri parseMpUnreach(final byte[] bytes) throws BGPParsingException;
+
public MpReachNlri parseMpReach(final byte[] bytes) throws BGPParsingException;
- // public byte[] serializeNlri(DataObject attribute);
+ // FIXME: PMD remove or put a comment what is this
+ // public byte[] serializeNlri(DataObject attribute);
}
private final static Logger logger = LoggerFactory.getLogger(AbstractMessageRegistry.class);
protected abstract Notification parseBody(final int type, final byte[] body, final int messageLength) throws BGPDocumentedException;
+
protected abstract byte[] serializeMessageImpl(final Notification message);
@Override
throw new IllegalArgumentException("Too few bytes in passed array. Passed: " + bytes.length + ". Expected: >= "
+ MessageUtil.COMMON_HEADER_LENGTH + ".");
}
- /*
- * byte array starts with message length
- */
- // final byte[] ones = new byte[MARKER_LENGTH];
- // Arrays.fill(ones, (byte)0xff);
- // if (Arrays.equals(bytes, ones))
+ final byte[] marker = ByteArray.subByte(bytes, 0, MessageUtil.MARKER_LENGTH);
+ final byte[] ones = new byte[MessageUtil.MARKER_LENGTH];
+ Arrays.fill(ones, (byte) 0xff);
+ // TODO: possible refactor
+ // if (Arrays.equals(marker, ones)) {
// throw new BGPDocumentedException("Marker not set to ones.", BGPError.CONNECTION_NOT_SYNC);
+ // }
final byte[] bs = ByteArray.cutBytes(bytes, MessageUtil.MARKER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(bs, 0, MessageUtil.LENGTH_FIELD_LENGTH));
final int messageType = UnsignedBytes.toInt(bs[MessageUtil.LENGTH_FIELD_LENGTH]);
protected final SimpleMessageRegistry msgReg = new SimpleMessageRegistry();
protected final SimpleSubsequentAddressFamilyRegistry safiReg = new SimpleSubsequentAddressFamilyRegistry();
protected final SimpleParameterRegistry paramReg = new SimpleParameterRegistry();
- protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(afiReg, safiReg);
+ protected final SimpleNlriRegistry nlriReg = new SimpleNlriRegistry(this.afiReg, this.safiReg);
@Override
public final AddressFamilyRegistry getAddressFamilyRegistry() {
- return afiReg;
+ return this.afiReg;
}
@Override
public final AttributeRegistry getAttributeRegistry() {
- return attrReg;
+ return this.attrReg;
}
@Override
public final CapabilityRegistry getCapabilityRegistry() {
- return capReg;
+ return this.capReg;
}
@Override
public final MessageRegistry getMessageRegistry() {
- return msgReg;
+ return this.msgReg;
}
@Override
public final NlriRegistry getNlriRegistry() {
- return nlriReg;
+ return this.nlriReg;
}
@Override
public final ParameterRegistry getParameterRegistry() {
- return paramReg;
+ return this.paramReg;
}
@Override
public final SubsequentAddressFamilyRegistry getSubsequentAddressFamilyRegistry() {
- return safiReg;
+ return this.safiReg;
}
}
package org.opendaylight.protocol.bgp.rib.impl;
import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
public final class Activator extends AbstractBindingAwareProvider {
+ @SuppressWarnings("unused")
private RIBImpl rib;
-
@Override
public void onSessionInitiated(final ProviderContext session) {
- rib = new RIBImpl(session.getSALService(DataProviderService.class));
+ this.rib = new RIBImpl(session.getSALService(DataProviderService.class));
}
}
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
- + +
| |
- + +
+ | |
+ | |
| Marker |
- + +
+ | |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length | Type |
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.PathAttributes;
-
/**
* This comparator is intended to implement BGP Best Path Selection algorithm, as described at
*
@Override
public int compare(final PathAttributes o1, final PathAttributes o2) {
- if (o1 == o2) {
- return 0;
- }
if (o1 == null) {
return 1;
}
if (o2 == null) {
return -1;
}
+ if (o1.equals(o2)) {
+ return 0;
+ }
// FIXME: look at ASPath
// FIXME: look at everything else :-)
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; // 240
/**
* Internal session state.
/**
* System.nanoTime value about when was sent the last message Protected to be updated also in tests.
*/
+ @VisibleForTesting
protected long lastMessageSentAt;
/**
this.stateTimer = Preconditions.checkNotNull(timer);
this.channel = Preconditions.checkNotNull(channel);
this.keepAlive = remoteOpen.getHoldTimer() / 3;
+ holdTimerValue = remoteOpen.getHoldTimer();
final Set<BgpTableType> tts = Sets.newHashSet();
if (remoteOpen.getBgpParameters() != null) {
}
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());
switch (this.state) {
case Finished:
case Idle:
- final Notify fsm_error = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
+ final Notify fsmError = new NotifyBuilder().setErrorCode(BGPError.FSM_ERROR.getCode()).setErrorSubcode(
BGPError.FSM_ERROR.getSubcode()).build();
- this.channel.writeAndFlush(fsm_error);
+ this.channel.writeAndFlush(fsmError);
case OpenConfirm:
if (msg instanceof Keepalive) {
negotiationSuccessful(this.session);
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.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.c.parameters.CAs4BytesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.open.bgp.parameters.c.parameters.c.as4.bytes.As4BytesCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.open.bgp.parameters.c.parameters.CMultiprotocolBuilder;
this.bgpId = bgpId;
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(LinkstateSubsequentAddressFamily.class).build()));
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CMultiprotocolBuilder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build());
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CMultiprotocolBuilder().setMultiprotocolCapability(
+ new MultiprotocolCapabilityBuilder().setAfi(LinkstateAddressFamily.class).setSafi(
+ LinkstateSubsequentAddressFamily.class).build()).build()).build());
// final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
// tableTypes.put(ipv4, true);
// tableTypes.put(linkstate,true);
// tlvs.add(new GracefulCapability(true, 0, tableTypes));
- tlvs.add((BgpParameters) new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(
- new AsNumber((long) as)).build()));
+ tlvs.add(new BgpParametersBuilder().setCParameters(
+ new CAs4BytesBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) as)).build()).build()).build());
this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
}
import org.opendaylight.protocol.util.ByteArray;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.NotifyBuilder;
import org.opendaylight.yangtools.yang.binding.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
*/
@ThreadSafe
public final class BGPMock implements BGP, Closeable {
+
+ private final static Logger logger = LoggerFactory.getLogger(BGPMock.class);
+
static final Notification connectionLostMagicMessage = new NotifyBuilder().setErrorCode(BGPError.CEASE.getCode()).build();
@GuardedBy("this")
messages.add(parser.parse(body));
}
} catch (final DeserializerException e) {
- e.printStackTrace();
+ logger.warn(e.getMessage(), e);
} catch (final DocumentedException e) {
- e.printStackTrace();
+ logger.warn(e.getMessage(), e);
}
return messages;
}
* This class has @Subscribe annotated methods which receive events from {@link EventBus} . Events are produced by
* {@link BGPMock}, and each instance notifies exactly one {@link BGPSessionListener}.
*/
-class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
+final class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
private final EventBus eventBus;
public static EventBusRegistration createAndRegister(final EventBus eventBus, final BGPSessionListener listener,
@ThreadSafe
public abstract class AbstractAdjRIBsIn<ID, DATA extends DataObject> implements AdjRIBsIn {
protected abstract class RIBEntryData {
- final PathAttributes attributes;
+ private final PathAttributes attributes;
protected RIBEntryData(final PathAttributes attributes) {
this.attributes = Preconditions.checkNotNull(attributes);
}
+ public PathAttributes getPathAttributes() {
+ return this.attributes;
+ }
+
protected abstract DATA getDataObject(ID key);
}
/**
- * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based on
- * ordering specified by the supplied comparator.
- *
+ * A single RIB table entry, which holds multiple versions of the entry's state and elects the authoritative based
+ * on ordering specified by the supplied comparator.
+ *
*/
private final class RIBEntry {
/*
}
private InstanceIdentifier<?> getName() {
- if (name == null) {
- name = identifierForKey(basePath, key);
+ if (this.name == null) {
+ this.name = identifierForKey(AbstractAdjRIBsIn.this.basePath, this.key);
}
- return name;
+ return this.name;
}
private RIBEntryData findCandidate(final RIBEntryData initial) {
RIBEntryData newState = initial;
for (final RIBEntryData s : this.candidates.values()) {
- if (newState == null || comparator.compare(newState.attributes, s.attributes) > 0) {
+ if (newState == null || AbstractAdjRIBsIn.this.comparator.compare(newState.attributes, s.attributes) > 0) {
newState = s;
}
}
private void electCandidate(final DataModificationTransaction transaction, final RIBEntryData candidate) {
if (this.currentState == null || !this.currentState.equals(candidate)) {
- transaction.putRuntimeData(getName(), candidate.getDataObject(key));
+ transaction.putRuntimeData(getName(), candidate.getDataObject(this.key));
this.currentState = candidate;
}
}
electCandidate(transaction, candidate);
return true;
} else {
- transaction.removeRuntimeData(name);
+ transaction.removeRuntimeData(this.name);
return false;
}
}
- synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData state) {
+ synchronized void setState(final DataModificationTransaction transaction, final Peer peer, final RIBEntryData state) {
this.candidates.put(peer, state);
electCandidate(transaction, findCandidate(state));
}
protected AbstractAdjRIBsIn(final Comparator<PathAttributes> comparator, final TablesKey key) {
this.comparator = Preconditions.checkNotNull(comparator);
- basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
+ this.basePath = InstanceIdentifier.builder().node(LocRib.class).node(Tables.class, key).toInstance();
}
@Override
protected abstract InstanceIdentifier<?> identifierForKey(final InstanceIdentifier<?> basePath, final ID id);
- protected synchronized void add(final DataModificationTransaction trans, final Peer peer, final ID id, final RIBEntryData data) {
+ protected synchronized void add(final DataModificationTransaction trans, final Peer peer, final ID id, final RIBEntryData data) {
RIBEntry e = this.entries.get(id);
if (e == null) {
e = new RIBEntry(id);
e.setState(trans, peer, data);
}
- protected synchronized void remove(final DataModificationTransaction trans, final Peer peer, final ID id) {
+ protected synchronized void remove(final DataModificationTransaction trans, final Peer peer, final ID id) {
final RIBEntry e = this.entries.get(id);
if (e != null && e.removeState(trans, peer)) {
this.entries.remove(id);
private final static Logger logger = LoggerFactory.getLogger(Main.class);
- public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
- + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ 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"
+ + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
+ "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
"With no parameters, this help is printed.";
- BGPDispatcherImpl dispatcher;
+ private final BGPDispatcherImpl dispatcher;
public Main() throws Exception {
- this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(
- ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
+ this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()));
}
public static void main(final String[] args) throws Exception {
as = new AsNumber(Long.valueOf(args[i + 1]));
i++;
} else {
- System.out.println("WARNING: Unrecognized argument: " + args[i]);
+ logger.error("WARNING: Unrecognized argument: " + args[i]);
}
i++;
}
public final class BinaryBGPDumpFileParser {
private static final byte ff = (byte) 255;
- private static final Logger LOG = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
+ private static final Logger logger = LoggerFactory.getLogger(BinaryBGPDumpFileParser.class);
private static final int MINIMAL_LENGTH = 19;
+ private BinaryBGPDumpFileParser() {
+
+ }
+
/**
* Extract BGP messages from binary file in MRT format.
*
}
}
- LOG.info("Succesfully extracted " + messages.size() + " messages");
+ logger.info("Succesfully extracted {} messages", messages.size());
return messages;
}
}
import com.google.common.io.CharStreams;
/**
- * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff marker.
- * New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to this format.
+ * Read text file, parse BGP messages. File can contain comments or other data. BGP messages are detected using 16 ff
+ * marker. New lines and spaces are ignored. Use {@link ByteArray#bytesToHexString(byte[])} for serializing bytes to
+ * this format.
*/
@Immutable
public class HexDumpBGPFileParser {
private static final int MINIMAL_LENGTH = 19;
- private static final Logger LOG = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
+ private static final Logger logger = LoggerFactory.getLogger(HexDumpBGPFileParser.class);
private static final String ff_16 = Strings.repeat("FF", 16);
+ private HexDumpBGPFileParser() {
+
+ }
+
public static List<byte[]> parseMessages(final File file) throws FileNotFoundException, IOException {
Preconditions.checkArgument(file != null, "Filename cannot be null");
return parseMessages(new FileInputStream(file));
}
public static List<byte[]> parseMessages(String content) {
- content = clearWhiteSpace_toUpper(content);
+ content = clearWhiteSpaceToUpper(content);
// search for 16 FFs
- List<byte[]> messages = Lists.newLinkedList();
+ final List<byte[]> messages = Lists.newLinkedList();
int idx = 0;
while ((idx = content.indexOf(ff_16, idx)) > -1) {
// next 2 bytes are length
- int lengthIdx = idx + 16 * 2;
- int messageIdx = lengthIdx + 4;
- String hexLength = content.substring(lengthIdx, messageIdx);
+ final int lengthIdx = idx + 16 * 2;
+ final int messageIdx = lengthIdx + 4;
+ final String hexLength = content.substring(lengthIdx, messageIdx);
byte[] byteLength = null;
try {
byteLength = Hex.decodeHex(hexLength.toCharArray());
- } catch (DecoderException e) {
+ } catch (final DecoderException e) {
throw new RuntimeException(e);
}
- int length = ByteArray.bytesToInt(byteLength);
- int messageEndIdx = idx + length * 2;
+ final int length = ByteArray.bytesToInt(byteLength);
+ final int messageEndIdx = idx + length * 2;
// Assert that message is longer than minimum 19(header.length == 19)
// If length in BGP message would be 0, loop would never end
- Preconditions.checkArgument(length >= MINIMAL_LENGTH,
- "Invalid message at index " + idx
- + ", length atribute is lower than " + MINIMAL_LENGTH);
+ Preconditions.checkArgument(length >= MINIMAL_LENGTH, "Invalid message at index " + idx + ", length atribute is lower than "
+ + MINIMAL_LENGTH);
- String hexMessage = content.substring(idx, messageEndIdx);
+ final String hexMessage = content.substring(idx, messageEndIdx);
byte[] message = null;
try {
message = Hex.decodeHex(hexMessage.toCharArray());
- } catch (DecoderException e) {
+ } catch (final DecoderException e) {
new RuntimeException(e);
}
messages.add(message);
idx = messageEndIdx;
}
- LOG.info("Succesfully extracted " + messages.size() + " messages");
+ logger.info("Succesfully extracted {} messages", messages.size());
return messages;
}
@VisibleForTesting
- static String clearWhiteSpace_toUpper(final String line){
+ static String clearWhiteSpaceToUpper(final String line) {
return line.replaceAll("\\s", "").toUpperCase();
}
@Test
public void testCleanWhiteSpace() {
final String input = "abc def\r\nghi\nj";
- assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpace_toUpper(input));
+ assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpaceToUpper(input));
}
@Test