use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder in project bgpcep by opendaylight.
the class AttributesEqualTests method testAfiSafiIn.
@Test
public void testAfiSafiIn() {
Statement statement = this.basicStatements.stream().filter(st -> st.getName().equals("afi-safi-in-test")).findFirst().get();
RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(350)).build()).build());
RouteAttributeContainer result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV6UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNotNull(result.getAttributes());
attributeContainer = routeAttributeContainerFalse(new AttributesBuilder().setLocalPref(new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build()).build());
result = this.statementRegistry.applyExportStatement(this.baseAttributes, IPV4UNICAST.class, this.exportParameters, attributeContainer, statement);
assertNull(result.getAttributes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder in project bgpcep by opendaylight.
the class SynchronizationAndExceptionTest method testHandleMessageAfterException.
@Test
public void testHandleMessageAfterException() {
final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy());
final RIBImpl ribImpl = new RIBImpl(this.tableRegistry, new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), this.ribExtension, this.serverDispatcher, this.codecsRegistry, this.domBroker, this.policies, ImmutableList.of(this.ipv4tt), pathTables);
ribImpl.instantiateServiceInstance();
final BGPPeer bgpPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, neighbor.getIpv4AddressNoZone(), ribImpl, null, PeerRole.Ibgp, this.serverRegistry, AFI_SAFIS_ADVERTIZED, Collections.emptySet());
bgpPeer.instantiateServiceInstance();
final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer().toJava(), 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 Ipv4AddressNoZone("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(Uint32.valueOf(100)).build()).build());
bgpSession.handleMessage(correct.build());
verify(this.tx, times(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
bgpSession.handleMessage(wrongMessage.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(2)).merge(eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
verify(this.tx).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(PEER_PATH));
verify(this.tx, times(0)).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(TABLE_PATH), eq(ImmutableNodes.leafNode(UPTODATE_NID, Boolean.TRUE)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder in project bgpcep by opendaylight.
the class PeerTest method testClassicPeer.
@Test
public void testClassicPeer() throws Exception {
this.classic = AbstractAddPathTest.configurePeer(this.tableRegistry, this.neighborAddress.getIpv4AddressNoZone(), getRib(), null, PeerRole.Ibgp, new StrictBGPPeerRegistry());
this.classic.instantiateServiceInstance();
this.mockSession();
assertEquals(this.neighborAddress.getIpv4AddressNoZone().getValue(), this.classic.getName());
this.classic.onSessionUp(this.session);
assertEquals("BGPPeer{name=127.0.0.1, tables=[TablesKey{_afi=interface org.opendaylight.yang.gen.v1" + ".urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily," + " _safi=interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types" + ".rev200120.UnicastSubsequentAddressFamily}]}", this.classic.toString());
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 ub = new UpdateBuilder();
ub.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 Ipv4AddressNoZone("127.0.0.1")).build()).build();
final AttributesBuilder ab = new AttributesBuilder();
ub.setAttributes(ab.setOrigin(origin).setAsPath(asPath).setCNextHop(nextHop).build());
try {
this.classic.onMessage(this.session, ub.build());
fail();
} catch (final BGPDocumentedException e) {
assertEquals(BGPError.MANDATORY_ATTR_MISSING_MSG + "LOCAL_PREF", e.getMessage());
assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING.getCode(), e.getError().getCode());
assertEquals(BGPError.WELL_KNOWN_ATTR_MISSING.getSubcode(), e.getError().getSubcode());
assertArrayEquals(new byte[] { LocalPreferenceAttributeParser.TYPE }, e.getData());
}
assertEquals(0, this.routes.size());
final LocalPref localPref = new LocalPrefBuilder().setPref(Uint32.valueOf(100)).build();
ub.setAttributes(ab.setLocalPref(localPref).build());
this.classic.onMessage(this.session, ub.build());
assertEquals(3, this.routes.size());
// create new peer so that it gets advertized routes from RIB
final BGPPeer testingPeer = AbstractAddPathTest.configurePeer(this.tableRegistry, this.neighborAddress.getIpv4AddressNoZone(), getRib(), null, PeerRole.Ibgp, new StrictBGPPeerRegistry());
testingPeer.instantiateServiceInstance();
testingPeer.onSessionUp(this.session);
assertEquals(3, this.routes.size());
final Nlri n11 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final Nlri n22 = new NlriBuilder().setPrefix(new Ipv4Prefix("8.0.1.16/28")).build();
final List<Nlri> nlris2 = Lists.newArrayList(n11, n22);
ub.setNlri(nlris2);
final WithdrawnRoutes w1 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("8.0.1.0/28")).build();
final WithdrawnRoutes w2 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build();
final WithdrawnRoutes w3 = new WithdrawnRoutesBuilder().setPrefix(new Ipv4Prefix("2.2.2.2/24")).build();
final List<WithdrawnRoutes> wrs = Lists.newArrayList(w1, w2, w3);
ub.setWithdrawnRoutes(wrs);
this.classic.onMessage(this.session, ub.build());
assertEquals(2, this.routes.size());
this.classic.onMessage(this.session, new KeepaliveBuilder().build());
this.classic.onMessage(this.session, new UpdateBuilder().setAttributes(new AttributesBuilder().addAugmentation(new AttributesUnreachBuilder().setMpUnreachNlri(new MpUnreachNlriBuilder().setAfi(IPV4_AFI).setSafi(SAFI).build()).build()).build()).build());
this.classic.onMessage(this.session, new RouteRefreshBuilder().setAfi(IPV4_AFI).setSafi(SAFI).build());
this.classic.onMessage(this.session, new RouteRefreshBuilder().setAfi(Ipv6AddressFamily.class).setSafi(SAFI).build());
assertEquals(2, this.routes.size());
this.classic.releaseConnection();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder in project bgpcep by opendaylight.
the class LocalPreferenceAttributeParserTest method testParseEmptyAttribute.
@Test
public void testParseEmptyAttribute() {
final ByteBuf actual = Unpooled.buffer();
registry.serializeAttribute(new AttributesBuilder().setLocalPref(new LocalPrefBuilder().build()).build(), actual);
assertEquals(Unpooled.buffer(), actual);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPrefBuilder in project bgpcep by opendaylight.
the class ParserTest method testBGPLink.
/*
* Tests BGP Link Ipv4
*
* 00 00 <- withdrawn routes length
* 01 48 <- total path attribute length (328)
* 90 <- attribute flags
0e <- attribute type code (MP reach)
01 2c <- attribute extended length (300)
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 02 <- NLRI type (2 - linkNLRI)
00 5d <- NLRI length (93)
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
01 01 <- remote node descriptor type (257)
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
01 03 <- link descriptor type (IPv4 interface address - 259)
00 04 <- length (4)
0b 0b 0b 03 <- value (11.11.11.3)
00 02 <- NLRI type (2 - linkNLRI)
00 5d <- NLRI length (93)
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
01 01 <- remote node descriptor type (257)
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
01 03 <- link descriptor type (IPv4 interface address - 259)
00 04 <- length
0b 0b 0b 01 <- value (11.11.11.1)
00 02 <- NLRI type (2 - linkNLRI)
00 5d <- NLRI length (93)
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
01 01 <- remote node descriptor type (257)
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
01 03 <- link descriptor type (IPv4 interface address - 259)
00 04 <- length
0b 0b 0b 01 <- value (11.11.11.1)
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
c0 <- attribute flags
1D <- attribute type (Link STATE - 29)
07 <- length
04 47 <- link attribute (1095 - Metric)
00 03 <- length
00 00 01 <- value
*/
@Test
public void testBGPLink() throws Exception {
final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(1), MessageUtil.COMMON_HEADER_LENGTH);
final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH));
final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null);
final UpdateBuilder builder = new UpdateBuilder();
// check fields
assertNull(message.getWithdrawnRoutes());
final Ipv4NextHopCase nextHop = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4AddressNoZone("25.25.25.1")).build()).build();
final LocalNodeDescriptorsBuilder ndBuilder = new LocalNodeDescriptorsBuilder().setAsNumber(new AsNumber(Uint32.valueOf(100))).setDomainId(new DomainIdentifier(Uint32.valueOf(0x19191901L))).setAreaId(new AreaIdentifier(Uint32.ZERO));
final RemoteNodeDescriptorsBuilder rdBuilder = new RemoteNodeDescriptorsBuilder().setAsNumber(new AsNumber(Uint32.valueOf(100))).setDomainId(new DomainIdentifier(Uint32.valueOf(0x19191901L))).setAreaId(new AreaIdentifier(Uint32.ZERO));
final CLinkstateDestinationBuilder clBuilder = new CLinkstateDestinationBuilder();
clBuilder.setIdentifier(new Identifier(Uint64.ONE));
clBuilder.setProtocolId(ProtocolId.Ospf);
final AttributesReachBuilder lsBuilder = new AttributesReachBuilder();
final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
mpBuilder.setAfi(LinkstateAddressFamily.class);
mpBuilder.setSafi(LinkstateSubsequentAddressFamily.class);
mpBuilder.setCNextHop(nextHop);
final List<CLinkstateDestination> linkstates = new ArrayList<>();
final LinkCaseBuilder lCase = new LinkCaseBuilder().setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(Uint32.valueOf(0x03030304L)).setLanInterface(new OspfInterfaceIdentifier(Uint32.valueOf(0x0b0b0b03L))).build()).build()).build());
lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(Uint32.valueOf(0x03030304L)).build()).build()).build());
lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier(new Ipv4AddressNoZone("11.11.11.3"))).build());
linkstates.add(clBuilder.setObjectType(lCase.build()).build());
lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(Uint32.valueOf(0x01010102L)).build()).build()).build());
lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier(new Ipv4AddressNoZone("11.11.11.1"))).build());
linkstates.add(clBuilder.setObjectType(lCase.build()).build());
lCase.setLocalNodeDescriptors(ndBuilder.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(Uint32.valueOf(0x01010102L)).build()).build()).build());
lCase.setRemoteNodeDescriptors(rdBuilder.setCRouterIdentifier(new OspfPseudonodeCaseBuilder().setOspfPseudonode(new OspfPseudonodeBuilder().setOspfRouterId(Uint32.valueOf(0x03030304L)).setLanInterface(new OspfInterfaceIdentifier(Uint32.valueOf(0x0b0b0b03L))).build()).build()).build());
linkstates.add(clBuilder.setObjectType(lCase.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(Uint32.valueOf(100)).build());
assertEquals(paBuilder.getLocalPref(), attrs.getLocalPref());
final MpReachNlri mp = attrs.augmentation(AttributesReach.class).getMpReachNlri();
assertEquals(mpBuilder.getAfi(), mp.getAfi());
assertEquals(mpBuilder.getSafi(), mp.getSafi());
assertEquals(mpBuilder.getCNextHop(), mp.getCNextHop());
final DestinationLinkstateBuilder dBuilder = new DestinationLinkstateBuilder();
dBuilder.setCLinkstateDestination(linkstates);
mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(new DestinationLinkstateCaseBuilder().setDestinationLinkstate(dBuilder.build()).build()).build());
lsBuilder.setMpReachNlri(mpBuilder.build());
paBuilder.addAugmentation(lsBuilder.build());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1Builder();
lsAttrBuilder.setLinkStateAttribute(new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder().setMetric(new Metric(Uint32.ONE)).build()).build());
paBuilder.addAugmentation(lsAttrBuilder.build());
paBuilder.setUnrecognizedAttributes(Collections.emptyMap());
assertEquals(lsAttrBuilder.build(), attrs.augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Attributes1.class));
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(INPUT_BYTES.get(1), ByteArray.readAllBytes(buffer));
}
Aggregations