use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib in project onos by opennetworkinglab.
the class BgpLocalRibImpl method selectionProcessNode.
/**
* Selection process for local RIB node.
*
* @param nlri NLRI to update
* @param isVpnRib true if VPN local RIB, otherwise false
* @throws BgpParseException throws BGP parse exception
*/
public void selectionProcessNode(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
BgpPeerImpl peer;
BgpSessionInfo sessionInfo;
int decisionResult;
boolean containsKey;
BgpNodeLSIdentifier nodeLsIdentifier = ((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors();
/* Here, we are checking if the given node is contained in the AdjacencyRib of any peer
or not. If none of the peer's AdjacencyRib has it, node can be marked for deletion.
*/
boolean shouldDeleteNode = false;
if (nodeTree.containsKey(nodeLsIdentifier)) {
shouldDeleteNode = true;
}
for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
if (nodeTree.containsKey(nodeLsIdentifier)) {
containsKey = (!isVpnRib) ? (peer.adjacencyRib().nodeTree().containsKey(nodeLsIdentifier)) : (peer.vpnAdjacencyRib().nodeTree().containsKey(nodeLsIdentifier));
if (!containsKey) {
continue;
}
sessionInfo = peer.sessionInfo();
PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), (!isVpnRib) ? (peer.adjacencyRib().nodeTree().get(nodeLsIdentifier)) : (peer.vpnAdjacencyRib().nodeTree().get(nodeLsIdentifier)));
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
if (decisionResult < 0) {
nodeTree.replace(nodeLsIdentifier, detailsLocRib);
log.debug("Local RIB node updated: {}", detailsLocRib.toString());
}
shouldDeleteNode = false;
}
}
if (shouldDeleteNode) {
log.debug("Local RIB delete node: {}", nodeLsIdentifier.toString());
for (BgpNodeListener l : bgpController.listener()) {
l.deleteNode((BgpNodeLSNlriVer4) nlri);
}
nodeTree.remove(nodeLsIdentifier);
bgpController.notifyTopologyChange();
}
}
use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib 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.PathAttrNlriDetailsLocalRib in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage4.
/**
* Peer1 has Node NLRI and Peer2 has Node NLRI with different MpReach and MpUnReach with VPN.
*/
@Test
public void testBgpUpdateMessage4() throws InterruptedException {
// Initiate the connections
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
short afi = 16388;
byte res = 0;
byte safi = (byte) 0x80;
bgpControllerImpl.getConfig().setLsCapability(true);
BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.35", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
IpAddress ipAddress = IpAddress.valueOf("127.0.0.35");
BgpId bgpId = new BgpId(ipAddress);
BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
LinkedList<BgpValueType> subTlvs1 = new LinkedList<>();
LinkedList<BgpValueType> subTlvs = new LinkedList<>();
BgpValueType tlv = AutonomousSystemTlv.of(2478);
subTlvs.add(tlv);
tlv = BgpLSIdentifierTlv.of(33686018);
subTlvs.add(tlv);
NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256);
BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes);
RouteDistinguisher rd = new RouteDistinguisher((long) 0x0A);
VpnAdjRibIn vpnAdj = peer.vpnAdjRib();
// In Adj-RIB, vpnNodeTree should contain rd
assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true));
Map<BgpNodeLSIdentifier, PathAttrNlriDetails> treeValue = vpnAdj.vpnNodeTree().get(rd);
// In Adj-RIB, vpnNodeTree should contain rd key which contains specified value
assertThat(treeValue.containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
// In Local-RIB, vpnNodeTree should contain rd
assertThat(obj.vpnNodeTree().containsKey(rd), is(true));
Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> value = obj.vpnNodeTree().get(rd);
// In Local-RIB, vpnNodeTree should contain rd key which contains specified value
assertThat(value.containsKey(key), is(true));
peer2.peerChannelHandler.asNumber = 200;
peer2.peerChannelHandler.version = 4;
peer2.peerChannelHandler.holdTime = 120;
bgpControllerImpl.getConfig().setLsCapability(true);
tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.40", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer2
bgpId = new BgpId(IpAddress.valueOf("127.0.0.40"));
peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
tlv = AutonomousSystemTlv.of(686);
subTlvs1.add(tlv);
tlv = BgpLSIdentifierTlv.of(33686018);
subTlvs1.add(tlv);
nodeDes = new NodeDescriptors(subTlvs1, (short) 0x10, (short) 256);
key = new BgpNodeLSIdentifier(nodeDes);
vpnAdj = peer.vpnAdjRib();
// In Adj-RIB, vpnNodeTree should contain rd
assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true));
treeValue = vpnAdj.vpnNodeTree().get(rd);
// In Adj-RIB, vpnNodeTree should contain rd key which contains specified value
assertThat(treeValue.containsKey(key), is(true));
// Disconnect peer1
channel.disconnect();
channel.close();
obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
// In Local-RIB, vpnNodeTree should contain rd
assertThat(obj.vpnNodeTree().containsKey(rd), is(true));
value = obj.vpnNodeTree().get(rd);
// In Local-RIB, vpnNodeTree should contain rd key which contains specified value
assertThat(value.containsKey(key), is(true));
}
use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage9.
/**
* Peer1 has Node NLRI (MpReach) and Peer2 has node NLRI with different MpReach
* and MpUnReach with IsIsNonPseudonode.
*/
@Test
public void testBgpUpdateMessage9() throws InterruptedException {
// Initiate the connections
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
short afi = 16388;
byte res = 0;
byte safi = (byte) 0x80;
bgpControllerImpl.getConfig().setLsCapability(true);
BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.30", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.30"));
BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
LinkedList<BgpValueType> subTlvs = new LinkedList<>();
BgpValueType tlv = AutonomousSystemTlv.of(2478);
subTlvs.add(tlv);
tlv = BgpLSIdentifierTlv.of(33686018);
subTlvs.add(tlv);
NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256);
BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes);
RouteDistinguisher rd = new RouteDistinguisher((long) 0x0A);
VpnAdjRibIn vpnAdj = peer.vpnAdjRib();
// In Adj-RIB, vpnNodeTree should contain specified rd
assertThat(vpnAdj.vpnNodeTree().containsKey(rd), is(true));
Map<BgpNodeLSIdentifier, PathAttrNlriDetails> treeValue = vpnAdj.vpnNodeTree().get(rd);
// In Adj-RIB, vpnNodeTree should contain specified rd with specified value
assertThat(treeValue.containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
// In Local-RIB, vpnNodeTree should contain specified rd
assertThat(obj.vpnNodeTree().containsKey(rd), is(true));
Map<BgpNodeLSIdentifier, PathAttrNlriDetailsLocalRib> value = obj.vpnNodeTree().get(rd);
// In Local-RIB, vpnNodeTree should contain specified rd with specified value
assertThat(value.containsKey(key), is(true));
peer2.peerChannelHandler.asNumber = 200;
peer2.peerChannelHandler.version = 4;
peer2.peerChannelHandler.holdTime = 120;
bgpControllerImpl.getConfig().setLsCapability(true);
tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer2.peerChannelHandler.capabilityTlv.add(tempTlv1);
peer2.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.50", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer2
bgpId = new BgpId(IpAddress.valueOf("127.0.0.50"));
peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
key = new BgpNodeLSIdentifier(nodeDes);
vpnAdj = peer.vpnAdjRib();
// In Adj-RIB, vpnNodeTree should be empty
assertThat(vpnAdj.vpnNodeTree().isEmpty(), is(true));
// peer1 disconnects
channel.disconnect();
channel.close();
obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRibVpn();
TimeUnit.MILLISECONDS.sleep(200);
// In Local-RIB, vpnNodeTree should be empty
assertThat(obj.vpnNodeTree().isEmpty(), is(true));
}
use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetailsLocalRib 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());
}
}
}
Aggregations