use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class PCEPTopologySessionListenerTest method testPCEPTopologySessionListener.
@Test
public void testPCEPTopologySessionListener() throws Exception {
listener.onSessionUp(session);
final PcepSessionState listenerState = listener.listenerState;
assertEquals(testAddress, listenerState.getPeerPref().getIpAddress());
final LocalPref state = listener.listenerState.getLocalPref();
assertNotNull(state);
assertEquals(DEAD_TIMER, state.getDeadtimer().shortValue());
assertEquals(KEEP_ALIVE, state.getKeepalive().shortValue());
assertEquals(0, state.getSessionId().intValue());
assertEquals(testAddress, state.getIpAddress());
final PeerPref peerState = listenerState.getPeerPref();
assertEquals(DEAD_TIMER, peerState.getDeadtimer().shortValue());
assertEquals(KEEP_ALIVE, peerState.getKeepalive().shortValue());
assertEquals(0, peerState.getSessionId().intValue());
assertEquals(testAddress, peerState.getIpAddress());
// add-lsp
topologyRpcs.addLsp(createAddLspInput());
assertEquals(1, receivedMsgs.size());
assertTrue(receivedMsgs.get(0) instanceof Pcinitiate);
final Pcinitiate pcinitiate = (Pcinitiate) receivedMsgs.get(0);
final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
final Uint32 srpId = req.getSrp().getOperationId().getValue();
final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true, testAddress, testAddress, testAddress, Optional.empty());
final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(Uint32.ONE)).setSync(FALSE).setRemove(FALSE).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(FALSE).build(), Optional.of(MsgBuilderUtil.createSrp(Uint32.ZERO)), null);
listener.onMessage(session, esm);
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertEquals(testAddress, pcc.getIpAddress().getIpv4AddressNoZone().getValue());
// reported lsp so far empty, has not received response (PcRpt) yet
assertNull(pcc.getReportedLsp());
return pcc;
});
listener.onMessage(session, pcRpt);
// check created lsp
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertEquals(1, pcc.nonnullReportedLsp().size());
final ReportedLsp reportedLsp = pcc.getReportedLsp().values().iterator().next();
assertEquals(tunnelName, reportedLsp.getName());
assertEquals(1, reportedLsp.nonnullPath().size());
final Path path = reportedLsp.nonnullPath().values().iterator().next();
assertEquals(1, path.getEro().getSubobject().size());
assertEquals(eroIpPrefix, getLastEroIpPrefix(path.getEro()));
return pcc;
});
// check stats
checkEquals(() -> assertEquals(1, listenerState.getDelegatedLspsCount().intValue()));
checkEquals(() -> assertTrue(listener.isSessionSynchronized()));
checkEquals(() -> assertTrue(listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getLastReceivedRptMsgTimestamp().toJava() > 0));
checkEquals(() -> assertEquals(2, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getReceivedRptMsgCount().intValue()));
checkEquals(() -> assertEquals(1, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentInitMsgCount().intValue()));
checkEquals(() -> assertEquals(0, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentUpdMsgCount().intValue()));
// update-lsp
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.update.lsp.args.ArgumentsBuilder();
updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
updArgsBuilder.addAugmentation(new Arguments3Builder().setLsp(new LspBuilder().setDelegate(TRUE).setAdministrative(FALSE).build()).build());
final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(tunnelName).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
topologyRpcs.updateLsp(update);
assertEquals(2, receivedMsgs.size());
assertTrue(receivedMsgs.get(1) instanceof Pcupd);
final Pcupd updateMsg = (Pcupd) receivedMsgs.get(1);
final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
final Uint32 srpId2 = upd.getSrp().getOperationId().getValue();
final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false, newDestinationAddress, testAddress, testAddress, Optional.empty());
final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2).setSync(TRUE).setRemove(FALSE).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath().getEro().getSubobject()));
listener.onMessage(session, pcRpt2);
// check updated lsp
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertEquals(1, pcc.getReportedLsp().size());
final ReportedLsp reportedLsp = pcc.getReportedLsp().values().iterator().next();
assertEquals(tunnelName, reportedLsp.getName());
assertEquals(1, reportedLsp.getPath().size());
final Path path = reportedLsp.getPath().values().iterator().next();
assertEquals(2, path.getEro().getSubobject().size());
assertEquals(dstIpPrefix, getLastEroIpPrefix(path.getEro()));
assertEquals(1, listenerState.getDelegatedLspsCount().intValue());
assertTrue(listener.isSessionSynchronized());
final StatefulMessagesStatsAug statefulstate = listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class);
assertTrue(statefulstate.getLastReceivedRptMsgTimestamp().toJava() > 0);
assertEquals(3, statefulstate.getReceivedRptMsgCount().intValue());
assertEquals(1, statefulstate.getSentInitMsgCount().intValue());
assertEquals(1, statefulstate.getSentUpdMsgCount().intValue());
final ReplyTime replyTime = listenerState.getMessages().getReplyTime();
assertTrue(replyTime.getAverageTime().toJava() > 0);
assertTrue(replyTime.getMaxTime().toJava() > 0);
final StatefulCapabilitiesStatsAug statefulCapabilities = listenerState.getPeerCapabilities().augmentation(StatefulCapabilitiesStatsAug.class);
assertFalse(statefulCapabilities.getActive());
assertTrue(statefulCapabilities.getInstantiation());
assertTrue(statefulCapabilities.getStateful());
return pcc;
});
// ensure-operational
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.ensure.lsp.operational.args.ArgumentsBuilder();
ensureArgs.addAugmentation(new Arguments1Builder().setOperational(OperationalStatus.Active).build());
final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(tunnelName).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
final OperationResult result = topologyRpcs.ensureLspOperational(ensure).get().getResult();
// check result
assertNull(result.getFailure());
// remove-lsp
final RemoveLspInput remove = new RemoveLspInputBuilder().setName(tunnelName).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
topologyRpcs.removeLsp(remove);
assertEquals(3, receivedMsgs.size());
assertTrue(receivedMsgs.get(2) instanceof Pcinitiate);
final Pcinitiate pcinitiate2 = (Pcinitiate) receivedMsgs.get(2);
final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
final Uint32 srpId3 = req2.getSrp().getOperationId().getValue();
final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false, testAddress, testAddress, testAddress, Optional.empty());
final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3).setRemove(TRUE).setSync(TRUE).setOperational(OperationalStatus.Down).build(), Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.emptyList()));
listener.onMessage(session, pcRpt3);
// check if lsp was removed
readDataOperational(getDataBroker(), pathComputationClientIId, pcc -> {
assertNull(pcc.getReportedLsp());
return pcc;
});
// check stats
checkEquals(() -> assertEquals(0, listenerState.getDelegatedLspsCount().intValue()));
checkEquals(() -> assertTrue(listener.isSessionSynchronized()));
checkEquals(() -> assertTrue(listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getLastReceivedRptMsgTimestamp().toJava() > 0));
checkEquals(() -> assertEquals(4, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getReceivedRptMsgCount().intValue()));
checkEquals(() -> assertEquals(2, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentInitMsgCount().intValue()));
checkEquals(() -> assertEquals(1, listenerState.getMessages().augmentation(StatefulMessagesStatsAug.class).getSentUpdMsgCount().intValue()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class BestPathStateImpl method resolveValues.
private void resolveValues() {
if (resolved) {
return;
}
final NamespaceSpecificIds ids = PATH_CACHE.getUnchecked(attributes.getIdentifier().getNodeType().getModule());
localPref = (Uint32) NormalizedNodes.findNode(attributes, ids.locPref).map(NormalizedNode::body).orElse(null);
final Optional<NormalizedNode> maybeMultiExitDisc = NormalizedNodes.findNode(attributes, ids.med);
if (maybeMultiExitDisc.isPresent()) {
multiExitDisc = ((Uint32) maybeMultiExitDisc.get().body()).toJava();
} else {
multiExitDisc = 0L;
}
final Optional<NormalizedNode> maybeOrigin = NormalizedNodes.findNode(attributes, ids.orig);
if (maybeOrigin.isPresent()) {
final String originStr = (String) maybeOrigin.get().body();
origin = BgpOrigin.forName(originStr).orElseThrow(() -> new IllegalArgumentException("Unhandled origin value " + originStr));
} else {
origin = null;
}
final Optional<NormalizedNode> maybeSegments = NormalizedNodes.findNode(attributes, ids.asPath);
if (maybeSegments.isPresent()) {
final UnkeyedListNode segments = (UnkeyedListNode) maybeSegments.get();
final List<Segments> segs = extractSegments(segments, ids);
if (!segs.isEmpty()) {
this.peerAs = BesthPathStateUtil.getPeerAs(segs);
this.asPathLength = countAsPath(segs);
}
}
final Optional<NormalizedNode> maybeCommunities = NormalizedNodes.findNode(attributes, ids.communities);
if (maybeCommunities.isPresent()) {
depreferenced = ((UnkeyedListNode) maybeCommunities.orElseThrow()).body().stream().anyMatch(community -> isStale(ids, community));
} else {
depreferenced = false;
}
this.resolved = true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.LocalPref 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();
}
Aggregations