use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class ComplementaryTest method testBGPAggregatorImpl.
@Test
public void testBGPAggregatorImpl() {
final BgpAggregator ipv4 = new AggregatorBuilder().setAsNumber(new AsNumber((long) 5524)).setNetworkAddress(new Ipv4Address("124.55.42.1")).build();
final BgpAggregator ipv4i = new AggregatorBuilder().setAsNumber(new AsNumber((long) 5525)).setNetworkAddress(new Ipv4Address("124.55.42.1")).build();
assertNotSame(ipv4.hashCode(), ipv4i.hashCode());
assertNotSame(ipv4.getAsNumber(), ipv4i.getAsNumber());
assertEquals(ipv4.getNetworkAddress(), ipv4i.getNetworkAddress());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class ComplementaryTest method testBGPParameter.
@Test
public void testBGPParameter() {
final MultiprotocolCapability cap = new MultiprotocolCapabilityBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build();
final CParameters tlv1 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(cap).build()).build();
final MultiprotocolCapability cap1 = new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build();
final CParameters tlv2 = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(cap1).build()).build();
final List<Tables> tt = new ArrayList<>();
tt.add(new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build());
tt.add(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build());
final GracefulRestartCapability tlv3 = new GracefulRestartCapabilityBuilder().setRestartFlags(new RestartFlags(Boolean.FALSE)).setRestartTime(0).setTables(tt).build();
final CParameters tlv4 = new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build();
assertFalse(tlv3.getRestartFlags().isRestartState());
assertEquals(0, tlv3.getRestartTime().intValue());
assertFalse(tlv1.equals(tlv2));
assertNotSame(tlv1.hashCode(), tlv3.hashCode());
assertNotSame(tlv2.toString(), tlv3.toString());
assertEquals(tlv3.getTables(), tt);
assertEquals(cap.getSafi(), cap1.getSafi());
assertNotSame(cap.getAfi(), cap1.getAfi());
assertEquals(40, tlv4.getAs4BytesCapability().getAsNumber().getValue().longValue());
assertEquals(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber((long) 40)).build()).build(), tlv4);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class OpenTest method testSerializeOpen.
@Test
public void testSerializeOpen() throws Exception {
final List<OptionalCapabilities> optionalCapas = Lists.newArrayList();
final OptionalCapabilities optionalCapabilitiesBuilder = new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(1000L)).build()).addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().setRestartFlags(new GracefulRestartCapability.RestartFlags(false)).setRestartTime(0).setTables(Collections.emptyList()).build()).build()).build()).build();
optionalCapas.add(optionalCapabilitiesBuilder);
final List<BgpParameters> tlvs = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(optionalCapas).build());
final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4Address("127.0.0.1")).setMyAsNumber(30).setHoldTimer(3).setVersion(new ProtocolVersion((short) 4)).setBgpParameters(tlvs).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getParameterRegistry()).serializeMessage(open, msg);
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getParameterRegistry()).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length);
assertEquals(open.getBgpIdentifier(), openResult.getBgpIdentifier());
assertEquals(open.getHoldTimer(), openResult.getHoldTimer());
assertEquals(open.getMyAsNumber(), openResult.getMyAsNumber());
boolean grace = false;
if (openResult.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability() != null) {
grace = true;
}
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(!grace ? 1 : 0).getCParameters().getAs4BytesCapability());
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAugmentation(CParameters1.class).getGracefulRestartCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 1 : 0).getCParameters().getAugmentation(CParameters1.class).getGracefulRestartCapability());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class AggregatorAttributeParser method parseAttribute.
/**
* Parse {@link Aggregator} from bytes
*
* @param buffer byte buffer to be parsed
* @param builder AttributesBuilder into which parsed {@link Aggregator} will be set
*/
@Override
public void parseAttribute(final ByteBuf buffer, final AttributesBuilder builder) {
final AsNumber asNumber = this.refCache.getSharedReference(new AsNumber(buffer.readUnsignedInt()));
final Ipv4Address address = Ipv4Util.addressForByteBuf(buffer);
builder.setAggregator(new AggregatorBuilder().setAsNumber(asNumber).setNetworkAddress(address).build());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project bgpcep by opendaylight.
the class AsPathAttributeParser method parseAsPath.
/**
* Parses AS_PATH from bytes.
*
* @param refCache ReferenceCache shared reference of object
* @param buffer bytes to be parsed
* @return new ASPath object
* @throws BGPDocumentedException if there is no AS_SEQUENCE present (mandatory)
* @throws BGPParsingException
*/
private static AsPath parseAsPath(final ReferenceCache refCache, final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
if (!buffer.isReadable()) {
return EMPTY;
}
final ArrayList<Segments> ases = new ArrayList<>();
boolean isSequence = false;
while (buffer.isReadable()) {
final int type = buffer.readUnsignedByte();
final SegmentType segmentType = AsPathSegmentParser.parseType(type);
if (segmentType == null) {
throw new BGPParsingException("AS Path segment type unknown : " + type);
}
final int count = buffer.readUnsignedByte();
final List<AsNumber> asList = AsPathSegmentParser.parseAsSegment(refCache, count, buffer.readSlice(count * AsPathSegmentParser.AS_NUMBER_LENGTH));
if (segmentType == SegmentType.AS_SEQUENCE) {
ases.add(new SegmentsBuilder().setAsSequence(asList).build());
isSequence = true;
} else {
ases.add(new SegmentsBuilder().setAsSet(asList).build());
}
}
if (!isSequence) {
throw new BGPDocumentedException("AS_SEQUENCE must be present in AS_PATH attribute.", BGPError.AS_PATH_MALFORMED);
}
ases.trimToSize();
return new AsPathBuilder().setSegments(ases).build();
}
Aggregations