use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier in project onos by opennetworkinglab.
the class BgpLocalRibImpl method selectionProcessPrefix.
/**
* Selection process for local RIB prefix.
*
* @param nlri NLRI to update
* @param isVpnRib true if VPN local RIB, otherwise false
* @throws BgpParseException BGP parse exception
*/
public void selectionProcessPrefix(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
BgpPeerImpl peer;
BgpSessionInfo sessionInfo;
int decisionResult;
boolean containsKey;
BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
/* Here, we are checking if the given prefix is contained in the AdjacencyRib of any peer
or not. If none of the peer's AdjacencyRib has it, prefix can be marked for deletion.
*/
boolean shouldDeletePrefix = false;
if (prefixTree.containsKey(prefixIdentifier)) {
shouldDeletePrefix = true;
}
for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
if (prefixTree.containsKey(prefixIdentifier)) {
containsKey = (!isVpnRib) ? (peer.adjacencyRib().prefixTree().containsKey(prefixIdentifier)) : (peer.vpnAdjacencyRib().prefixTree().containsKey(prefixIdentifier));
if (!containsKey) {
continue;
}
sessionInfo = peer.sessionInfo();
PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), ((!isVpnRib) ? (peer.adjacencyRib().prefixTree().get(prefixIdentifier)) : (peer.vpnAdjacencyRib().prefixTree().get(prefixIdentifier))));
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
if (decisionResult < 0) {
prefixTree.replace(prefixIdentifier, detailsLocRib);
log.debug("Local RIB prefix updated: {}", detailsLocRib.toString());
}
shouldDeletePrefix = false;
}
if (shouldDeletePrefix) {
log.debug("Local RIB remove prefix: {}", prefixIdentifier.toString());
for (BgpPrefixListener l : bgpController.prefixListener()) {
l.deletePrefix((BgpPrefixIPv4LSNlriVer4) nlri);
}
prefixTree.remove(prefixIdentifier);
}
}
}
use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage8.
/**
* Peer1 has Prefix NLRI (MpReach).
*/
@Test
public void testBgpUpdateMessage8() throws InterruptedException {
// Initiate the connections
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 150;
short afi = 16388;
byte res = 0;
byte safi = 71;
bgpControllerImpl.getConfig().setLsCapability(true);
BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.20", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.20"));
BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
LinkedList<BgpValueType> subTlvs = new LinkedList<>();
BgpValueType tlv = AutonomousSystemTlv.of(2222);
subTlvs.add(tlv);
tlv = BgpLSIdentifierTlv.of(33686018);
subTlvs.add(tlv);
byte[] isoNodeID = new byte[] { 0x19, 0x21, 0x68, 0x07, 0x70, 0x01 };
tlv = IsIsNonPseudonode.of(isoNodeID);
subTlvs.add(tlv);
NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x1a, (short) 256);
LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>();
byte[] prefix = new byte[] { 0x20, (byte) 0xc0, (byte) 0xa8, 0x4d, 0x01 };
ChannelBuffer tempCb = ChannelBuffers.dynamicBuffer();
tempCb.writeBytes(prefix);
tlv = IPReachabilityInformationTlv.read(tempCb, (short) 5);
prefixDescriptor.add(tlv);
BgpPrefixLSIdentifier key = new BgpPrefixLSIdentifier(nodeDes, prefixDescriptor);
AdjRibIn adj = peer.adjRib();
// In Adj-RIB, prefixTree should contain specified key
assertThat(adj.prefixTree().containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
// In Local-RIB, prefixTree should contain specified key
assertThat(obj.prefixTree().containsKey(key), is(true));
}
use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier in project onos by opennetworkinglab.
the class BgpLocalRibImpl method add.
@Override
public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) throws BgpParseException {
int decisionResult;
log.debug("Add to local RIB {}", details.toString());
PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), details);
if (nlri instanceof BgpNodeLSNlriVer4) {
BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
if (nodeTree.containsKey(nodeLsIdentifier)) {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
if (decisionResult <= 0) {
for (BgpNodeListener l : bgpController.listener()) {
l.addNode((BgpNodeLSNlriVer4) nlri, details);
}
nodeTree.replace(nodeLsIdentifier, detailsLocRib);
log.debug("Local RIB update node: {}", detailsLocRib.toString());
}
} else {
nodeTree.put(nodeLsIdentifier, detailsLocRib);
for (BgpNodeListener l : bgpController.listener()) {
l.addNode((BgpNodeLSNlriVer4) nlri, details);
}
bgpController.notifyTopologyChange();
log.debug("Local RIB add node: {}", detailsLocRib.toString());
}
} else if (nlri instanceof BgpLinkLsNlriVer4) {
BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
if (linkTree.containsKey(linkLsIdentifier)) {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
if (decisionResult <= 0) {
linkTree.replace(linkLsIdentifier, detailsLocRib);
for (BgpLinkListener l : bgpController.linkListener()) {
l.addLink((BgpLinkLsNlriVer4) nlri, details);
}
log.debug("Local RIB update link: {}", detailsLocRib.toString());
}
} else {
linkTree.put(linkLsIdentifier, detailsLocRib);
for (BgpLinkListener l : bgpController.linkListener()) {
l.addLink((BgpLinkLsNlriVer4) nlri, details);
}
bgpController.notifyTopologyChange();
log.debug("Local RIB add link: {}", detailsLocRib.toString());
}
} else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
BgpPrefixLSIdentifier prefixIdentifier = ((BgpPrefixIPv4LSNlriVer4) nlri).getPrefixIdentifier();
if (prefixTree.containsKey(prefixIdentifier)) {
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
// Compare local RIB entry with the current attribute
decisionResult = selectionAlgo.compare(prefixTree.get(prefixIdentifier), detailsLocRib);
if (decisionResult <= 0) {
prefixTree.replace(prefixIdentifier, detailsLocRib);
for (BgpPrefixListener l : bgpController.prefixListener()) {
l.addPrefix((BgpPrefixIPv4LSNlriVer4) nlri, details);
}
log.debug("Local RIB update prefix: {}", detailsLocRib.toString());
}
} else {
prefixTree.put(prefixIdentifier, detailsLocRib);
for (BgpPrefixListener l : bgpController.prefixListener()) {
l.addPrefix((BgpPrefixIPv4LSNlriVer4) nlri, details);
}
log.debug("Local RIB add prefix: {}", detailsLocRib.toString());
}
}
}
use of org.onosproject.bgpio.protocol.linkstate.BgpPrefixLSIdentifier in project onos by opennetworkinglab.
the class BgpLocalRibImpl method localRibUpdatePrefix.
/**
* Update localRIB prefix based on available peer adjacency RIB.
*
* @param o instance of adjacency-in/VPN adjacency-in
* @throws BgpParseException BGP parse exception
*/
public void localRibUpdatePrefix(Object o) throws BgpParseException {
if (o instanceof AdjRibIn) {
AdjRibIn adjRib = (AdjRibIn) o;
log.debug("Update local RIB prefix.");
Set<BgpPrefixLSIdentifier> prefixKeys = adjRib.prefixTree().keySet();
for (BgpPrefixLSIdentifier key : prefixKeys) {
PathAttrNlriDetails pathAttrNlri = adjRib.prefixTree().get(key);
BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(pathAttrNlri.identifier(), pathAttrNlri.protocolID().getType(), key, null, false);
decisionProcess(prefixNlri);
}
}
if (o instanceof VpnAdjRibIn) {
VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
log.debug("Update local RIB VPN prefix.");
Set<RouteDistinguisher> prefixKeysVpn = vpnAdjRib.vpnPrefixTree().keySet();
Map<BgpPrefixLSIdentifier, PathAttrNlriDetails> prefix;
for (RouteDistinguisher keyVpnPrefix : prefixKeysVpn) {
prefix = vpnAdjRib.vpnPrefixTree().get(keyVpnPrefix);
Set<BgpPrefixLSIdentifier> vpnPrefixKeys = prefix.keySet();
for (BgpPrefixLSIdentifier key : vpnPrefixKeys) {
PathAttrNlriDetails pathAttrNlri = vpnAdjRib.prefixTree().get(key);
BgpPrefixIPv4LSNlriVer4 prefixNlri = new BgpPrefixIPv4LSNlriVer4(pathAttrNlri.identifier(), pathAttrNlri.protocolID().getType(), key, keyVpnPrefix, true);
decisionProcess(prefixNlri, keyVpnPrefix);
}
}
}
}
Aggregations