use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class PcepStateUtils method displayNodeState.
private static void displayNodeState(final String topologyId, final String nodeId, final PcepSessionState pcepSessionState, final PrintStream stream) {
final ShellTable table = new ShellTable();
table.column("Attribute").alignLeft();
table.column("Value").alignLeft();
showNodeState(table, topologyId, nodeId, pcepSessionState);
addHeader(table, "Local preferences");
final LocalPref localPref = pcepSessionState.getLocalPref();
showPreferences(table, localPref);
final PcepEntityIdStatsAug entAug = localPref.getAugmentation(PcepEntityIdStatsAug.class);
if (entAug != null) {
table.addRow().addContent("Speaker Entity Identifier", Arrays.toString(entAug.getSpeakerEntityIdValue()));
}
addHeader(table, "Peer preferences");
final PeerPref peerPref = pcepSessionState.getPeerPref();
showPreferences(table, peerPref);
showCapabilities(table, pcepSessionState.getPeerCapabilities());
final Messages messages = pcepSessionState.getMessages();
showMessages(table, messages);
final ErrorMessages error = messages.getErrorMessages();
showErrorMessages(table, error);
final ReplyTime reply = messages.getReplyTime();
showReplyMessages(table, reply);
table.print(stream);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class PCEPSessionImplTest method testSessionStatistics.
@Test
public void testSessionStatistics() {
this.session.handleMessage(Util.createErrorMessage(PCEPErrors.LSP_RSVP_ERROR, null));
Assert.assertEquals(this.ipAddress, this.session.getPeerPref().getIpAddress());
final PeerPref peerPref = this.session.getPeerPref();
Assert.assertEquals(this.ipAddress, peerPref.getIpAddress());
Assert.assertEquals(DEADTIMER, peerPref.getDeadtimer().shortValue());
Assert.assertEquals(KEEP_ALIVE, peerPref.getKeepalive().shortValue());
Assert.assertEquals(0, peerPref.getSessionId().intValue());
final LocalPref localPref = this.session.getLocalPref();
Assert.assertEquals(this.ipAddress, localPref.getIpAddress());
Assert.assertEquals(DEADTIMER, localPref.getDeadtimer().shortValue());
Assert.assertEquals(KEEP_ALIVE, localPref.getKeepalive().shortValue());
Assert.assertEquals(0, localPref.getSessionId().intValue());
final Messages msgs = this.session.getMessages();
Assert.assertEquals(1, msgs.getReceivedMsgCount().longValue());
Assert.assertEquals(0, msgs.getSentMsgCount().longValue());
Assert.assertEquals(0, msgs.getUnknownMsgReceived().longValue());
final ErrorMessages errMsgs = msgs.getErrorMessages();
Assert.assertEquals(1, errMsgs.getReceivedErrorMsgCount().intValue());
Assert.assertEquals(0, errMsgs.getSentErrorMsgCount().intValue());
Assert.assertEquals(PCEPErrors.LSP_RSVP_ERROR.getErrorType(), errMsgs.getLastReceivedError().getErrorType().shortValue());
Assert.assertEquals(PCEPErrors.LSP_RSVP_ERROR.getErrorValue(), errMsgs.getLastReceivedError().getErrorValue().shortValue());
this.session.sendMessage(Util.createErrorMessage(PCEPErrors.UNKNOWN_PLSP_ID, null));
final Messages msgs2 = this.session.getMessages();
Assert.assertEquals(1, msgs2.getReceivedMsgCount().longValue());
Assert.assertEquals(1, msgs2.getSentMsgCount().longValue());
Assert.assertEquals(0, msgs2.getUnknownMsgReceived().longValue());
final ErrorMessages errMsgs2 = msgs2.getErrorMessages();
Assert.assertEquals(1, errMsgs2.getReceivedErrorMsgCount().intValue());
Assert.assertEquals(1, errMsgs2.getSentErrorMsgCount().intValue());
Assert.assertEquals(PCEPErrors.UNKNOWN_PLSP_ID.getErrorType(), errMsgs2.getLastSentError().getErrorType().shortValue());
Assert.assertEquals(PCEPErrors.UNKNOWN_PLSP_ID.getErrorValue(), errMsgs2.getLastSentError().getErrorValue().shortValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class PCEPSessionState method getLocalPref.
private static LocalPref getLocalPref(final Open open, final Channel channel) {
final LocalPrefBuilder peerBuilder = new LocalPrefBuilder();
peerBuilder.setDeadtimer(open.getDeadTimer());
peerBuilder.setKeepalive(open.getKeepalive());
peerBuilder.setIpAddress(((InetSocketAddress) channel.localAddress()).getAddress().getHostAddress());
peerBuilder.setSessionId(open.getSessionId().intValue());
return peerBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class LocalPreferenceAttributeParser method serializeAttribute.
@Override
public void serializeAttribute(final DataObject attribute, final ByteBuf byteAggregator) {
Preconditions.checkArgument(attribute instanceof Attributes, "Attribute parameter is not a PathAttribute object.");
final LocalPref lp = ((Attributes) attribute).getLocalPref();
if (lp == null) {
return;
}
AttributeUtil.formatAttribute(AttributeUtil.TRANSITIVE, TYPE, Unpooled.copyInt(lp.getPref().intValue()), byteAggregator);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.LocalPref in project bgpcep by opendaylight.
the class PeerTest method testClassicPeer.
@Test
public void testClassicPeer() throws Exception {
this.classic = new BGPPeer(this.neighborAddress, getRib(), PeerRole.Ibgp, null, Collections.emptySet(), Collections.emptySet());
this.classic.instantiateServiceInstance();
this.mockSession();
assertEquals(this.neighborAddress.getIpv4Address().getValue(), this.classic.getName());
this.classic.onSessionUp(this.session);
Assert.assertArrayEquals(new byte[] { 1, 1, 1, 1 }, this.classic.getRawIdentifier());
assertEquals("BGPPeer{name=127.0.0.1, tables=[TablesKey{_afi=interface org.opendaylight.yang.gen.v1.urn" + ".opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily," + " _safi=interface org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types" + ".rev130919.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 Ipv4Address("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((long) 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 = new BGPPeer(this.neighborAddress, getRib(), PeerRole.Ibgp, null, Collections.emptySet(), Collections.emptySet());
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(Attributes2.class, new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder().setAfi(AFI).setSafi(SAFI).build()).build()).build()).build());
this.classic.onMessage(this.session, new RouteRefreshBuilder().setAfi(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