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 LinkstateNlriParserTest method testLinkNlri.
@Test
public void testLinkNlri() throws BGPParsingException {
setUp(this.linkNlri);
// test BA form
assertNull(this.dest.getDistinguisher());
assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
final LinkCase lCase = ((LinkCase) this.dest.getObjectType());
final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors();
assertEquals(new AsNumber(72L), local.getAsNumber());
assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId());
assertEquals(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42 })).build()).build(), local.getCRouterIdentifier());
assertEquals("1.1.1.1", local.getBgpRouterId().getValue());
assertEquals(new AsNumber(258L), local.getMemberAsn());
final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors();
assertEquals(new AsNumber(72L), remote.getAsNumber());
assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId());
assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build()).build(), remote.getCRouterIdentifier());
assertEquals(new AsNumber(259L), remote.getMemberAsn());
assertEquals("1.1.1.2", remote.getBgpRouterId().getValue());
final LinkDescriptors ld = lCase.getLinkDescriptors();
assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());
final ByteBuf buffer = Unpooled.buffer();
this.registry.serializeNlriType(this.dest, buffer);
assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));
// test BI form
final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);
final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
protocolId.withValue("isis-level2");
linkstateBI.addChild(protocolId.build());
final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
identifier.withValue(BigInteger.ONE);
linkstateBI.addChild(identifier.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);
// local node descriptors
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors = Builders.containerBuilder();
localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);
final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
asNumber.withValue(72L);
localNodeDescriptors.addChild(asNumber.build());
final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
domainID.withValue(0x28282828L);
localNodeDescriptors.addChild(domainID.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
crouterId.withNodeIdentifier(C_ROUTER_ID_NID);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);
final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
isoSystemID.withValue(new byte[] { 0, 0, 0, 0, 0, (byte) 0x42 });
isisNode.addChild(isoSystemID.build());
crouterId.addChild(isisNode.build());
localNodeDescriptors.addChild(crouterId.build());
final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
bgpRouterId.withValue("1.1.1.1");
final ImmutableLeafNodeBuilder<Long> memberAsn = new ImmutableLeafNodeBuilder<>();
memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
memberAsn.withValue(258L);
localNodeDescriptors.addChild(bgpRouterId.build());
localNodeDescriptors.addChild(memberAsn.build());
// remote descriptors
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors = Builders.containerBuilder();
remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
remoteNodeDescriptors.addChild(asNumber.build());
remoteNodeDescriptors.addChild(domainID.build());
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 = Builders.choiceBuilder();
crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> ospfNode = Builders.containerBuilder();
ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);
final ImmutableLeafNodeBuilder<Long> ospfRouterId = new ImmutableLeafNodeBuilder<>();
ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
ospfRouterId.withValue(0x00000040L);
ospfNode.addChild(ospfRouterId.build());
crouterId2.addChild(ospfNode.build());
remoteNodeDescriptors.addChild(crouterId2.build());
final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
bgpRouterIdRemote.withValue("1.1.1.2");
remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());
final ImmutableLeafNodeBuilder<Long> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
memberAsnRemote.withValue(259L);
remoteNodeDescriptors.addChild(memberAsnRemote.build());
// link descritpors
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> linkDescriptors = Builders.containerBuilder();
linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);
final ImmutableLeafNodeBuilder<Long> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
linkLocalIdentifier.withValue(16909060L);
final ImmutableLeafNodeBuilder<Long> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
linkRemoteIdentifier.withValue(168496141L);
final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
ipv4InterfaceAddress.withValue("197.20.160.42");
final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
ipv4NeighborAddress.withValue("197.20.160.40");
final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
multiTopologyId.withValue(3);
linkDescriptors.addChild(linkLocalIdentifier.build());
linkDescriptors.addChild(linkRemoteIdentifier.build());
linkDescriptors.addChild(ipv4InterfaceAddress.build());
linkDescriptors.addChild(ipv4NeighborAddress.build());
linkDescriptors.addChild(multiTopologyId.build());
objectType.addChild(localNodeDescriptors.build());
objectType.addChild(remoteNodeDescriptors.build());
objectType.addChild(linkDescriptors.build());
linkstateBI.addChild(objectType.build());
assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.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 ParserTest method testBGPNode.
/*
* TEST BGP Node
*
* 00 00 <- withdrawn routes length
00 b1 <- total path attribute length (177)
80 <- attribute flags
0e <- attribute type code (MP reach)
a0 <- attribute length (160)
40 04 <- AFI (16388 - Linkstate)
47 <- SAFI (71 - Linkstate)
04 <- next hop length
19 19 19 01 - nexthop (25.25.25.1)
00 <- reserved
00 01 <- NLRI type (1 - nodeNLRI)
00 31 <- NLRI length (49)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
01 00 <- local node descriptor type (256)
00 24 <- length (36)
02 00 <- node descriptor type (member AS - 512)
00 04 <- length
00 00 00 64 <- value (100)
02 01 <- node descriptor type (bgpId - 513)
00 04 <- length
19 19 19 01 <- bgpId (25.25.25.1)
02 02 <- node descriptor type (areaId - 514)
00 04 <- length
00 00 00 00 <- value
02 03 <- node descriptor type (routeId - 515)
00 08 <- length
03 03 03 04 0b 0b 0b 03 <- OSPF Router Id
00 01 <- NLRI type (1 - nodeNLRI)
00 2d <- NLRI length (45)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
01 00 <- local node descriptor type (256)
00 20 <- length (32)
02 00 <- node descriptor type (member AS - 512)
00 04 <- length
00 00 00 64 <- value (100)
02 01 <- node descriptor type (bgpId - 513)
00 04 <- length
19 19 19 01 <- bgpId (25.25.25.1)
02 02 <- node descriptor type (areaId - 514)
00 04 <- length
00 00 00 00 <- value
02 03 <- node descriptor type (routeId - 515)
00 04 <- length
03 03 03 04 <- OSPF Router Id
00 01 <- NLRI type (1 - nodeNLRI)
00 2d <- NLRI length (45)
03 <- ProtocolID - OSPF
00 00 00 00 00 00 00 01 <- identifier
01 00 <- local node descriptor type (256)
00 20 <- length (32)
02 00 <- node descriptor type (member AS - 512)
00 04 <- length
00 00 00 64 <- value (100)
02 01 <- node descriptor type (bgpId - 513)
00 04 <- length
19 19 19 01 <- bgpId (25.25.25.1)
02 02 <- node descriptor type (areaId - 514)
00 04 <- length
00 00 00 00 <- value
02 03 <- node descriptor type (routeId - 515)
00 04 <- length
01 01 01 02 <- OSPF Router Id
40 <- attribute flags
01 <- attribute type (Origin)
01 <- attribute length
00 <- value (IGP)
40 <- attribute flags
02 <- attribute type (AS Path)
00 <- length
40 <- attribute flags
05 <- attribute type (local pref)
04 <- length
00 00 00 64 <- value
*/
@Test
public void testBGPNode() throws Exception {
final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength);
final UpdateBuilder builder = new UpdateBuilder();
// check fields
assertNull(message.getWithdrawnRoutes());
// attributes
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("25.25.25.1")).build()).build();
final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
clBuilder.setIdentifier(new Identifier(BigInteger.ONE));
clBuilder.setProtocolId(ProtocolId.Ospf);
final NodeDescriptorsBuilder n = new NodeDescriptorsBuilder();
n.setAsNumber(new AsNumber((long) 100)).setDomainId(new DomainIdentifier(0x19191901L)).setAreaId(new AreaIdentifier(0L));
final List<CLinkstateDestination> linkstates = Lists.newArrayList();
final NodeCaseBuilder nCase = new NodeCaseBuilder();
nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(0x03030304L).setLanInterface(new OspfInterfaceIdentifier(0x0b0b0b03L)).build()).build()).build());
linkstates.add(clBuilder.setObjectType(nCase.build()).build());
nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x03030304L).build()).build()).build());
linkstates.add(clBuilder.setObjectType(nCase.build()).build());
nCase.setNodeDescriptors(n.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x01010102L).build()).build()).build());
linkstates.add(clBuilder.setObjectType(nCase.build()).build());
final Attributes1Builder lsBuilder = new Attributes1Builder();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(LinkstateAddressFamily.class);
mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
mpBuilder.setCNextHop(nextHop);
final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
dBuilder.setCLinkstateDestination(linkstates);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
lsBuilder.setMpReachNlri(mpBuilder.build());
// 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(Collections.emptyList()).build());
assertEquals(paBuilder.getAsPath(), attrs.getAsPath());
paBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
paBuilder.addAugmentation(Attributes1.class, lsBuilder.build());
paBuilder.setUnrecognizedAttributes(Collections.emptyList());
final MpReachNlri mp = attrs.getAugmentation(Attributes1.class).getMpReachNlri();
assertEquals(mpBuilder.getAfi(), mp.getAfi());
assertEquals(mpBuilder.getSafi(), mp.getSafi());
assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mp.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
assertEquals(linkstates.size(), dests.size());
assertEquals(linkstates, dests);
// check API message
builder.setAttributes(paBuilder.build());
assertEquals(builder.build(), message);
final ByteBuf buffer = Unpooled.buffer();
ParserTest.updateParser.serializeMessage(message, buffer);
assertArrayEquals(inputBytes.get(2), 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 AsPathPrepend method applyExportAction.
@Override
public Attributes applyExportAction(final RouteEntryBaseAttributes routeEntryInfo, final BGPRouteEntryExportParameters exportParameters, final Attributes attributes, final SetAsPathPrepend actions) {
final List<Segments> oldSegments = attributes.getAsPath().getSegments();
/*
* We need to check the first segment.
* If it has as-set then new as-sequence with local AS is prepended.
* If it has as-sequence, we may add local AS when it has less than 255 elements.
* Otherwise we need to create new as-sequence for local AS.
*/
final ArrayList<AsNumber> newAsSequence = new ArrayList<>();
newAsSequence.add(new AsNumber(routeEntryInfo.getLocalAs()));
List<Segments> newSegments = new ArrayList<>();
if (oldSegments == null || oldSegments.isEmpty()) {
newSegments = Collections.singletonList(new SegmentsBuilder().setAsSequence(newAsSequence).build());
} else {
final Segments firstSegment = oldSegments.remove(0);
final List<AsNumber> firstAsSequence = firstSegment.getAsSequence();
if (firstAsSequence != null && firstAsSequence.size() < Values.UNSIGNED_BYTE_MAX_VALUE) {
newAsSequence.addAll(firstAsSequence);
newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
} else {
newSegments.add(new SegmentsBuilder().setAsSequence(newAsSequence).build());
newSegments.add(firstSegment);
}
newSegments.addAll(oldSegments);
}
return new AttributesBuilder(attributes).setAsPath(new AsPathBuilder().setSegments(newSegments).build()).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 MatchAsPathSetHandler method matchAsPathSetCondition.
private boolean matchAsPathSetCondition(final AsPath asPath, final String asPathSetName, final MatchSetOptionsType matchSetOptions) {
if (asPath == null) {
return false;
}
final AsPathSet asPathSetFilter = this.sets.getUnchecked(StringUtils.substringBetween(asPathSetName, "=\"", "\""));
final List<Segments> segments = asPath.getSegments();
if (asPathSetFilter == null || segments == null) {
return false;
}
final List<AsNumber> l1 = segments.stream().map(AsPathSegment::getAsSequence).filter(Objects::nonNull).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
final List<AsNumber> l2 = segments.stream().map(AsPathSegment::getAsSet).filter(Objects::nonNull).flatMap(Collection::stream).filter(Objects::nonNull).collect(Collectors.toList());
List<AsNumber> allAs = Stream.of(l1, l2).flatMap(Collection::stream).collect(Collectors.toList());
final List<AsNumber> asPathSetFilterList = asPathSetFilter.getAsPathSetMember();
if (matchSetOptions.equals(MatchSetOptionsType.ALL)) {
return allAs.containsAll(asPathSetFilterList) && asPathSetFilterList.containsAll(allAs);
}
final boolean noneInCommon = Collections.disjoint(allAs, asPathSetFilterList);
if (matchSetOptions.equals(MatchSetOptionsType.ANY)) {
return !noneInCommon;
}
// (matchSetOptions.equals(MatchSetOptionsType.INVERT))
return noneInCommon;
}
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 BGPPeerBuilder method createPeer.
static void createPeer(final BGPDispatcher dispatcher, final Arguments arguments, final InetSocketAddress localAddress, final BGPSessionListener sessionListener, final BgpParameters bgpParameters) {
final AsNumber as = arguments.getAs();
final BGPSessionPreferences proposal = new BGPSessionPreferences(as, arguments.getHoldTimer(), new BgpId(localAddress.getAddress().getHostAddress()), as, Collections.singletonList(bgpParameters), Optional.empty());
final BGPPeerRegistry strictBGPPeerRegistry = dispatcher.getBGPPeerRegistry();
if (arguments.getInitiateConnection()) {
for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener, proposal);
addFutureListener(localAddress, ((BGPDispatcherImpl) dispatcher).createClient(localAddress, remoteAddress, RETRY_TIMER, true));
}
} else {
for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener, proposal);
}
addFutureListener(localAddress, dispatcher.createServer(localAddress));
}
LOG.debug("{} {}", sessionListener, proposal);
}
Aggregations