use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId in project bgpcep by opendaylight.
the class TestUtil method createRouteMirrorMsg.
public static RouteMirroringMessage createRouteMirrorMsg(final Ipv4Address bgpId) {
final RouteMirroringMessageBuilder routeMirrorMsgBuilder = new RouteMirroringMessageBuilder().setPeerHeader(createPeerHeader(bgpId));
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.mirror.TlvsBuilder tlvsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.mirror.TlvsBuilder();
tlvsBuilder.setMirrorInformationTlv(new MirrorInformationTlvBuilder().setCode(MirrorInformationCode.forValue(1)).build());
routeMirrorMsgBuilder.setTlvs(tlvsBuilder.build());
return routeMirrorMsgBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId in project bgpcep by opendaylight.
the class AbstractAddPathTest method configurePeer.
protected static BGPPeer configurePeer(final Ipv4Address peerAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole, final BGPPeerRegistry bgpPeerRegistry) {
final IpAddress ipAddress = new IpAddress(peerAddress);
final BGPPeer bgpPeer = new BGPPeer(new IpAddress(peerAddress), ribImpl, peerRole, null, AFI_SAFIS_ADVERTIZED, Collections.emptySet());
final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
bgpPeerRegistry.addPeer(ipAddress, bgpPeer, new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs));
bgpPeer.instantiateServiceInstance();
return bgpPeer;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId in project bgpcep by opendaylight.
the class SynchronizationAndExceptionTest method testUseCase1.
@Test
public void testUseCase1() {
final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy(this.peerTracker));
final RIBImpl ribImpl = new RIBImpl(new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), this.ribExtension, this.serverDispatcher, this.codecsRegistry, this.domBroker, getDataBroker(), this.policies, this.peerTracker, ImmutableList.of(this.ipv4tt), pathTables);
ribImpl.instantiateServiceInstance();
ribImpl.onGlobalContextUpdated(this.schemaContext);
final BGPPeer bgpPeer = new BGPPeer(neighbor, ribImpl, PeerRole.Ibgp, null, AFI_SAFIS_ADVERTIZED, Collections.emptySet());
bgpPeer.instantiateServiceInstance();
final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null);
bgpSession.setChannelExtMsgCoder(this.classicOpen);
bgpPeer.onSessionUp(bgpSession);
final Nlri n1 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final Nlri n2 = new NlriBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
final Nlri n3 = new NlriBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<Nlri> nlris = Lists.newArrayList(n1, n2, n3);
final UpdateBuilder wrongMessage = new UpdateBuilder();
wrongMessage.setNlri(nlris);
final Origin origin = new OriginBuilder().setValue(BgpOrigin.Igp).build();
final AsPath asPath = new AsPathBuilder().setSegments(Collections.emptyList()).build();
final CNextHop nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()).build();
final AttributesBuilder ab = new AttributesBuilder();
wrongMessage.setAttributes(ab.setOrigin(origin).setAsPath(asPath).setCNextHop(nextHop).build());
final UpdateBuilder correct = new UpdateBuilder(wrongMessage.build());
correct.setAttributes(ab.setLocalPref(new LocalPrefBuilder().setPref((long) 100).build()).build());
bgpSession.handleMessage(correct.build());
verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
bgpSession.handleMessage(new UpdateBuilder().build());
verify(this.tx, times(3)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
verify(this.tx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(TABLE_PATH), eq(ImmutableNodes.leafNode(ATTRIBUTES_UPTODATE_FALSE.getNodeType(), Boolean.TRUE)));
verify(this.tx, times(0)).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(PEER_PATH));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId in project bgpcep by opendaylight.
the class RibImpl method createRib.
private RIBImpl createRib(final Global global, final String bgpInstanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
this.afiSafi = getAfiSafiWithDefault(global.getAfiSafis(), true);
final Config globalConfig = global.getConfig();
this.asNumber = globalConfig.getAs();
this.routerId = globalConfig.getRouterId();
this.clusterId = getGlobalClusterIdentifier(globalConfig);
final BGPPeerTrackerImpl peerTracker = new BGPPeerTrackerImpl();
final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil.toPathSelectionMode(this.afiSafi, tableTypeRegistry, peerTracker).entrySet().stream().collect(Collectors.toMap(entry -> new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
final BGPRibRoutingPolicy ribPolicy = this.policyProvider.buildBGPRibPolicy(this.asNumber.getValue(), this.routerId, this.clusterId, RoutingPolicyUtil.getApplyPolicy(global.getApplyPolicy()));
final CodecsRegistryImpl codecsRegistry = CodecsRegistryImpl.create(codecTreeFactory, this.extensions.getClassLoadingStrategy());
return new RIBImpl(new RibId(bgpInstanceName), this.asNumber, new BgpId(this.routerId), this.extensions, this.dispatcher, codecsRegistry, this.domBroker, this.dataBroker, ribPolicy, peerTracker, toTableTypes(this.afiSafi, tableTypeRegistry), pathSelectionModes);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId 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));
}
Aggregations