use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber in project netvirt by opendaylight.
the class ConfigureBgpCli method addNeighbor.
protected void addNeighbor() {
if (!validateAsNumber(asNumber)) {
printAddNeighborHelp();
return;
}
boolean validIp = validateIp(ip);
if (!validIp) {
session.getConsole().println("invalid neighbor ip");
printAddNeighborHelp();
return;
}
TcpMd5SignaturePasswordType md5secret = null;
if (md5passwordOption != null) {
try {
md5secret = new TcpMd5SignaturePasswordType(md5passwordOption);
} catch (IllegalArgumentException e) {
session.getConsole().println(new StringBuilder("invalid MD5 password: ").append(e.getMessage()).toString());
printAddNeighborHelp();
return;
}
}
if (sourceIp != null) {
validIp = validateIp(sourceIp);
if (!validIp) {
session.getConsole().println("invalid source ip");
printAddNeighborHelp();
return;
}
}
if (ebgpMultihops != null) {
try {
long val = Long.parseLong(ebgpMultihops);
if (val < 1 || val > 255) {
session.getConsole().println("invalid ebgpMultihops number , valid range [1,255] ");
printAddNeighborHelp();
return;
}
} catch (NumberFormatException e) {
session.getConsole().println("invalid ebgpMultihops number, valid range [1-255]");
printAddNeighborHelp();
return;
}
}
if (addressFamily != null) {
try {
af_safi.valueOf(addressFamily);
} catch (IllegalArgumentException e) {
session.getConsole().println("invalid addressFamily valid values SAFI_IPV4_LABELED_UNICAST | SAFI_MPLS_VPN");
printAddNeighborHelp();
return;
}
}
if (getAsNumber(ip) != -1) {
session.getConsole().println("neighbor with ip " + ip + " already exists");
return;
}
bgpManager.addNeighbor(ip, Long.parseLong(asNumber), md5secret);
if (addressFamily != null) {
bgpManager.addAddressFamily(ip, af_afi.AFI_IP, af_safi.valueOf(addressFamily));
}
if (ebgpMultihops != null) {
bgpManager.addEbgpMultihop(ip, Integer.parseInt(ebgpMultihops));
}
if (sourceIp != null) {
bgpManager.addUpdateSource(ip, sourceIp);
}
}
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 APITest method testAsNumberUtil.
@Test
public void testAsNumberUtil() {
final List<BgpParameters> params = new ArrayList<>();
final List<OptionalCapabilities> capas = new ArrayList<>();
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().build()).build()).build()).build());
capas.add(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(35L)).build()).build()).build());
params.add(new BgpParametersBuilder().setOptionalCapabilities(capas).build());
final Open open1 = new OpenBuilder().setBgpParameters(params).build();
assertEquals(35L, AsNumberUtil.advertizedAsNumber(open1).getValue().longValue());
final Open open2 = new OpenBuilder().setMyAsNumber(10).build();
assertEquals(10, AsNumberUtil.advertizedAsNumber(open2).getValue().intValue());
}
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 BGPMessageParserMockTest method fillMessages.
/**
* Helper method to fill messages variable.
*
* @param asn this parameter is passed to ASNumber constructor
*/
private static Update fillMessages(final long asn) {
final UpdateBuilder builder = new UpdateBuilder();
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(Lists.newArrayList(new AsNumber(asn))).build());
final CNextHop nextHop = new Ipv6NextHopCaseBuilder().setIpv6NextHop(new Ipv6NextHopBuilder().setGlobal(new Ipv6Address("2001:db8::1")).setLinkLocal(new Ipv6Address("fe80::c001:bff:fe7e:0")).build()).build();
final Ipv6Prefix pref1 = new Ipv6Prefix("2001:db8:1:2::/64");
final Ipv6Prefix pref2 = new Ipv6Prefix("2001:db8:1:1::/64");
final Ipv6Prefix pref3 = new Ipv6Prefix("2001:db8:1::/64");
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
final MpReachNlriBuilder mpReachBuilder = new MpReachNlriBuilder();
mpReachBuilder.setAfi(Ipv6AddressFamily.class);
mpReachBuilder.setSafi(UnicastSubsequentAddressFamily.class);
mpReachBuilder.setCNextHop(nextHop);
mpReachBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(Lists.newArrayList(new Ipv6PrefixesBuilder().setPrefix(pref1).build(), new Ipv6PrefixesBuilder().setPrefix(pref2).build(), new Ipv6PrefixesBuilder().setPrefix(pref3).build())).build()).build()).build());
paBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(mpReachBuilder.build()).build());
builder.setAttributes(paBuilder.build());
return builder.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 BGPParserTest method testGetUpdateMessage1.
/*
* Tests IPv4 NEXT_HOP, ATOMIC_AGGREGATE, COMMUNITY, NLRI
*
* ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <- marker
* 00 54 <- length (84) - including header
* 02 <- message type
* 00 00 <- withdrawn routes length
* 00 31 <- total path attribute length (49)
* 40 <- attribute flags
* 01 <- attribute type code (origin)
* 01 <- attribute length
* 00 <- Origin value (IGP)
* 40 <- attribute flags
* 02 <- attribute type code (as path)
* 06 <- attribute length
* 02 <- AS_SEQUENCE
* 01 <- path segment count
* 00 00 fd ea <- path segment value (65002)
* 40 <- attribute flags
* 03 <- attribute type code (Next Hop)
* 04 <- attribute length
* 10 00 00 02 <- value (10.0.0.2)
* 80 <- attribute flags
* 04 <- attribute type code (multi exit disc)
* 04 <- attribute length
* 00 00 00 00 <- value
* 60 <- attribute flags
* 06 <- attribute type code (atomic aggregate)
* 00 <- attribute length
* 40 <- attribute flags
* 08 <- attribute type code (community)
* 10 <- attribute length FF FF FF
* 01 <- value (NO_EXPORT)
* FF FF FF 02 <- value (NO_ADVERTISE)
* FF FF FF 03 <- value (NO_EXPORT_SUBCONFED)
* FF FF FF 10 <- unknown Community
*
* //NLRI
* 18 ac 11 02 <- IPv4 Prefix (172.17.2.0 / 24)
* 18 ac 11 01 <- IPv4 Prefix (172.17.1.0 / 24)
* 18 ac 11 00 <- IPv4 Prefix (172.17.0.0 / 24)
*/
@Test
public void testGetUpdateMessage1() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = BGPParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final List<AsNumber> asNumbers = new ArrayList<>();
asNumbers.add(new AsNumber(65002L));
final List<Segments> asPath = Lists.newArrayList();
asPath.add(new SegmentsBuilder().setAsSequence(asNumbers).build());
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("10.0.0.2")).build()).build();
final List<Communities> comms = Lists.newArrayList();
comms.add((Communities) CommunityUtil.NO_EXPORT);
comms.add((Communities) CommunityUtil.NO_ADVERTISE);
comms.add((Communities) CommunityUtil.NO_EXPORT_SUBCONFED);
comms.add((Communities) CommunityUtil.create(NoopReferenceCache.getInstance(), 0xFFFF, 0xFF10));
final UpdateBuilder builder = new UpdateBuilder();
// check nlri
final List<Nlri> nlris = Lists.newArrayList();
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.2.0/24")).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.1.0/24")).build());
nlris.add(new NlriBuilder().setPrefix(new Ipv4Prefix("172.17.0.0/24")).build());
assertEquals(nlris, message.getNlri());
builder.setNlri(nlris);
// check path attributes
final Attributes attrs = message.getAttributes();
final AttributesBuilder paBuilder = new AttributesBuilder();
paBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
assertEquals(paBuilder.getOrigin(), attrs.getOrigin());
paBuilder.setAsPath(new AsPathBuilder().setSegments(asPath).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setCNextHop(nextHop);
assertEquals(paBuilder.getCNextHop(), attrs.getCNextHop());
paBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
assertEquals(paBuilder.getMultiExitDisc(), attrs.getMultiExitDisc());
paBuilder.setAtomicAggregate(new AtomicAggregateBuilder().build());
assertEquals(paBuilder.getAtomicAggregate(), attrs.getAtomicAggregate());
paBuilder.setCommunities(comms);
assertEquals(paBuilder.getCommunities(), attrs.getCommunities());
paBuilder.setUnrecognizedAttributes(Collections.emptyList());
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
BGPParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer));
}
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 AsPathSegmentParser method serializeAsList.
static void serializeAsList(final List<AsNumber> asList, final SegmentType type, final ByteBuf byteAggregator) {
if (asList == null) {
return;
}
byteAggregator.writeByte(serializeType(type));
byteAggregator.writeByte(asList.size());
for (final AsNumber asNumber : asList) {
byteAggregator.writeInt(asNumber.getValue().intValue());
}
}
Aggregations