use of org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier in project onos by opennetworkinglab.
the class BgpUpdateMsgTest method bgpUpdateMessageTest31.
/**
* This test case checks update message with MPUnreach.
*/
@Test
public void bgpUpdateMessageTest31() throws BgpParseException {
byte[] updateMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, // withdrawn routes
(byte) 0xff, // withdrawn routes
(byte) 0xff, // withdrawn routes
0x00, // withdrawn routes
0x5e, // withdrawn routes
0x02, // withdrawn routes
0x00, // withdrawn routes
0x04, // withdrawn routes
0x18, // withdrawn routes
0x0a, // withdrawn routes
0x01, // withdrawn routes
0x01, // path attribute len
0x00, // path attribute len
0x43, // origin
0x04, // origin
0x01, // origin
0x01, // origin
0x00, // as_path
0x40, // as_path
0x02, // as_path
0x04, // as_path
0x02, // as_path
0x01, // as_path
(byte) 0xfd, // as_path
(byte) 0xe9, // med
(byte) 0x80, // med
0x04, // med
0x04, // med
0x00, // med
0x00, // med
0x00, // med
0x00, // mpunreach with safi = 71
(byte) 0x80, // mpunreach with safi = 71
0x0f, // mpunreach with safi = 71
0x2e, // mpunreach with safi = 71
0x40, // mpunreach with safi = 71
0x04, // mpunreach with safi = 71
0x47, 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, // node nlri
0x58 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(updateMsg);
BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
BgpMessage message;
BgpHeader bgpHeader = new BgpHeader();
message = reader.readFrom(buffer, bgpHeader);
assertThat(message, instanceOf(BgpUpdateMsg.class));
BgpUpdateMsg other = (BgpUpdateMsg) message;
assertThat(other.getHeader().getMarker(), is(MARKER));
assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
assertThat(other.getHeader().getLength(), is((short) 94));
ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
byte[] prefix = new byte[] { 0x0a, 0x01, 0x01, 0x00 };
IpPrefix testPrefixValue = listIterator1.next();
assertThat(testPrefixValue.prefixLength(), is((int) 24));
assertThat(testPrefixValue.address().toOctets(), is(prefix));
BgpValueType testPathAttribute;
Origin origin;
AsPath asPath;
Med med;
MpUnReachNlri mpUnReach;
List<BgpValueType> pathAttributes = new LinkedList<>();
BgpPathAttributes actualpathAttribute = other.bgpPathAttributes();
pathAttributes = actualpathAttribute.pathAttributes();
ListIterator<BgpValueType> listIterator = pathAttributes.listIterator();
OriginType originValue = OriginType.IGP;
testPathAttribute = listIterator.next();
origin = (Origin) testPathAttribute;
assertThat(origin.origin(), is(originValue));
testPathAttribute = listIterator.next();
asPath = (AsPath) testPathAttribute;
ListIterator<Short> listIterator2 = asPath.asPathSeq().listIterator();
assertThat(listIterator2.next(), is((short) 65001));
testPathAttribute = listIterator.next();
med = (Med) testPathAttribute;
assertThat(med.med(), is(0));
testPathAttribute = listIterator.next();
mpUnReach = (MpUnReachNlri) testPathAttribute;
assertThat(mpUnReach.mpUnReachNlriLen(), is((int) 46));
assertThat(mpUnReach.getType(), is((short) 15));
List<BgpLSNlri> testMpUnReachNlri = new LinkedList<>();
testMpUnReachNlri = mpUnReach.mpUnReachNlri();
ListIterator<BgpLSNlri> list1 = testMpUnReachNlri.listIterator();
BgpLSNlri testnlri = list1.next();
NlriType nlriType = org.onosproject.bgpio.protocol.NlriType.NODE;
ProtocolType protocolId = org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO;
assertThat(testnlri.getIdentifier(), is((long) 0));
assertThat(testnlri.getNlriType(), is(nlriType));
assertThat(testnlri.getProtocolId(), is(protocolId));
BgpNodeLSNlriVer4 testNodenlri = (BgpNodeLSNlriVer4) testnlri;
BgpNodeLSIdentifier testLocalNodeDescriptors = testNodenlri.getLocalNodeDescriptors();
List<BgpValueType> testSubTlvs = new LinkedList<>();
NodeDescriptors localNodeDescriptors = testLocalNodeDescriptors.getNodedescriptors();
testSubTlvs = localNodeDescriptors.getSubTlvs();
ListIterator<BgpValueType> subtlvlist1 = testSubTlvs.listIterator();
AutonomousSystemTlv testAutonomousSystemTlv = (AutonomousSystemTlv) subtlvlist1.next();
assertThat(testAutonomousSystemTlv.getAsNum(), is(2222));
assertThat(testAutonomousSystemTlv.getType(), is((short) 512));
BgpLSIdentifierTlv testBgpLsIdentifierTlv = (BgpLSIdentifierTlv) subtlvlist1.next();
assertThat(testBgpLsIdentifierTlv.getBgpLsIdentifier(), is(33686018));
assertThat(testBgpLsIdentifierTlv.getType(), is((short) 513));
IsIsNonPseudonode testIsIsNonPseudonode = (IsIsNonPseudonode) subtlvlist1.next();
byte[] expIsoNodeId = new byte[] { 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58 };
assertThat(testIsIsNonPseudonode.getIsoNodeId(), is(expIsoNodeId));
assertThat(testIsIsNonPseudonode.getType(), is((short) 515));
}
use of org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier 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.BgpNodeLSIdentifier 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.BgpNodeLSIdentifier in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage6.
/**
* Peer2 has Prefix NLRI (MpReach).
*/
@Test
public void testBgpUpdateMessage6() 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 = 71;
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.94", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.94"));
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);
TimeUnit.MILLISECONDS.sleep(500);
AdjRibIn adj = peer.adjRib();
// In Adj-RIB, nodeTree should contain specified key
assertThat(adj.nodeTree().containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
// In Local-RIB, nodeTree should contain specified key
assertThat(obj.nodeTree().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.80", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer2
bgpId = new BgpId(IpAddress.valueOf("127.0.0.80"));
peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
TimeUnit.MILLISECONDS.sleep(500);
adj = peer.adjRib();
// In Adj-RIB, nodeTree should contain specified key
assertThat(adj.nodeTree().containsKey(key), is(true));
// peer1 disconnects
channel.disconnect();
channel.close();
obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
TimeUnit.MILLISECONDS.sleep(200);
// In Local-RIB, nodeTree should contain specified key
assertThat(obj.nodeTree().containsKey(key), is(true));
}
use of org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier 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));
}
Aggregations