use of org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage3.
/**
* Peer1 has Link NLRI (MpReach).
*/
@Test
public void testBgpUpdateMessage3() throws InterruptedException, TestUtilsException {
// Initiate the connections
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
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.10", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.10"));
BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
LinkedList<BgpValueType> localNodeSubTlvs = new LinkedList<>();
LinkedList<BgpValueType> remoteNodeSubTlvs = new LinkedList<>();
BgpValueType tlv = AutonomousSystemTlv.of(2222);
localNodeSubTlvs.add(tlv);
remoteNodeSubTlvs.add(tlv);
tlv = BgpLSIdentifierTlv.of(33686018);
localNodeSubTlvs.add(tlv);
remoteNodeSubTlvs.add(tlv);
byte[] isoNodeID = new byte[] { 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 };
tlv = IsIsPseudonode.of(isoNodeID, (byte) 0x03);
localNodeSubTlvs.add(tlv);
isoNodeID = new byte[] { 0x19, 0x00, (byte) 0x95, 0x02, 0x50, 0x21 };
tlv = IsIsNonPseudonode.of(isoNodeID);
remoteNodeSubTlvs.add(tlv);
NodeDescriptors localNodeDes = new NodeDescriptors(localNodeSubTlvs, (short) 0x1b, (short) 256);
NodeDescriptors remoteNodeDes = new NodeDescriptors(remoteNodeSubTlvs, (short) 0x1a, (short) 0x101);
LinkedList<BgpValueType> linkDescriptor = new LinkedList<>();
tlv = IPv4AddressTlv.of(Ip4Address.valueOf("2.2.2.2"), (short) 0x103);
linkDescriptor.add(tlv);
BgpLinkLSIdentifier key = new BgpLinkLSIdentifier(localNodeDes, remoteNodeDes, linkDescriptor);
TimeUnit.MILLISECONDS.sleep(200);
AdjRibIn adj = peer.adjRib();
// In Adj-RIB, linkTree should contain specified key
assertThat(adj.linkTree().containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
TimeUnit.MILLISECONDS.sleep(200);
// In Local-RIB, linkTree should contain specified key
assertThat(obj.linkTree().containsKey(key), is(true));
}
use of org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier in project onos by opennetworkinglab.
the class BgpLocalRibImpl method localRibUpdateLink.
/**
* Update localRIB link based on available peer adjacency RIB.
*
* @param o adjacency-in/VPN adjacency-in
* @throws BgpParseException BGP parse exceptions
*/
public void localRibUpdateLink(Object o) throws BgpParseException {
if (o instanceof AdjRibIn) {
AdjRibIn adjRib = (AdjRibIn) o;
log.debug("Update local RIB link.");
Set<BgpLinkLSIdentifier> linkKeys = adjRib.linkTree().keySet();
for (BgpLinkLSIdentifier key : linkKeys) {
PathAttrNlriDetails pathAttrNlri = adjRib.linkTree().get(key);
BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(), pathAttrNlri.identifier(), key, null, false);
decisionProcess(linkNlri);
}
}
if (o instanceof VpnAdjRibIn) {
VpnAdjRibIn vpnAdjRib = (VpnAdjRibIn) o;
log.debug("Update local RIB VPN link");
Set<RouteDistinguisher> linkKeysVpn = vpnAdjRib.vpnLinkTree().keySet();
Map<BgpLinkLSIdentifier, PathAttrNlriDetails> link;
for (RouteDistinguisher keyVpnLink : linkKeysVpn) {
link = vpnAdjRib.vpnLinkTree().get(keyVpnLink);
Set<BgpLinkLSIdentifier> vpnLinkKeys = link.keySet();
for (BgpLinkLSIdentifier key : vpnLinkKeys) {
PathAttrNlriDetails pathAttrNlri = vpnAdjRib.linkTree().get(key);
BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4(pathAttrNlri.protocolID().getType(), pathAttrNlri.identifier(), key, keyVpnLink, true);
decisionProcess(linkNlri, keyVpnLink);
}
}
}
}
use of org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier 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.BgpLinkLSIdentifier in project onos by opennetworkinglab.
the class BgpLocalRibImpl method selectionProcessLink.
/**
* Selection process for local RIB link.
*
* @param nlri NLRI to update
* @param isVpnRib true if VPN local RIB, otherwise false
* @throws BgpParseException BGP parse exception
*/
public void selectionProcessLink(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
BgpPeerImpl peer;
BgpSessionInfo sessionInfo;
int decisionResult;
boolean containsKey;
BgpLinkLSIdentifier linkLsIdentifier = ((BgpLinkLsNlriVer4) nlri).getLinkIdentifier();
/* Here, we are checking if the given link is contained in the AdjacencyRib of any peer
or not. If none of the peer's AdjacencyRib has it, link can be marked for deletion.
*/
boolean shouldDeleteLink = false;
if (linkTree.containsKey(linkLsIdentifier)) {
shouldDeleteLink = true;
}
for (BgpId bgpId : bgpController.connectedPeers().keySet()) {
peer = (BgpPeerImpl) (bgpController.getPeer(bgpId));
if (linkTree.containsKey(linkLsIdentifier)) {
containsKey = (!isVpnRib) ? (peer.adjacencyRib().linkTree().containsKey(linkLsIdentifier)) : (peer.vpnAdjacencyRib().linkTree().containsKey(linkLsIdentifier));
if (!containsKey) {
continue;
}
sessionInfo = peer.sessionInfo();
PathAttrNlriDetailsLocalRib detailsLocRib = new PathAttrNlriDetailsLocalRib(sessionInfo.remoteBgpId().ipAddress(), sessionInfo.remoteBgpIdentifier(), sessionInfo.remoteBgpASNum(), sessionInfo.isIbgpSession(), ((!isVpnRib) ? (peer.adjacencyRib().linkTree().get(linkLsIdentifier)) : (peer.vpnAdjacencyRib().linkTree().get(linkLsIdentifier))));
BgpSelectionAlgo selectionAlgo = new BgpSelectionAlgo();
decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
if (decisionResult < 0) {
linkTree.replace(linkLsIdentifier, detailsLocRib);
log.debug("Local RIB link updated: {}", detailsLocRib.toString());
}
shouldDeleteLink = false;
}
}
if (shouldDeleteLink) {
log.debug("Local RIB remove link: {}", linkLsIdentifier.toString());
for (BgpLinkListener l : bgpController.linkListener()) {
l.deleteLink((BgpLinkLsNlriVer4) nlri);
}
linkTree.remove(linkLsIdentifier);
bgpController.notifyTopologyChange();
}
}
Aggregations