use of org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4 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.BgpNodeLSNlriVer4 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.BgpNodeLSNlriVer4 in project onos by opennetworkinglab.
the class BgpPeerImpl method callRemove.
/**
* Removes NLRI identifier node in a tree separately based on afi and safi.
*
* @param peerImpl BGP peer instance
* @param nlri NLRI information
* @throws BgpParseException BGP parse exception
*/
public void callRemove(BgpPeerImpl peerImpl, List<BgpLSNlri> nlri) throws BgpParseException {
ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
while (listIterator.hasNext()) {
BgpLSNlri nlriInfo = listIterator.next();
if (nlriInfo instanceof BgpNodeLSNlriVer4) {
if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) {
adjRib.remove(nlriInfo);
bgplocalRib.delete(nlriInfo);
} else {
vpnAdjRib.removeVpn(nlriInfo, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher());
bgplocalRibVpn.delete(nlriInfo, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher());
}
} else if (nlriInfo instanceof BgpLinkLsNlriVer4) {
if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) {
adjRib.remove(nlriInfo);
bgplocalRib.delete(nlriInfo);
} else {
vpnAdjRib.removeVpn(nlriInfo, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher());
bgplocalRibVpn.delete(nlriInfo, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher());
}
} else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) {
if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) {
adjRib.remove(nlriInfo);
bgplocalRib.delete(nlriInfo);
} else {
vpnAdjRib.removeVpn(nlriInfo, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher());
bgplocalRibVpn.delete(nlriInfo, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher());
}
}
}
}
use of org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4 in project onos by opennetworkinglab.
the class BgpPeerImpl method callAdd.
/**
* Updates NLRI identifier node in a tree separately based on afi and safi.
*
* @param peerImpl BGP peer instance
* @param nlri MpReachNlri path attribute
* @param pathAttr list of BGP path attributes
* @throws BgpParseException throws exception
*/
public void callAdd(BgpPeerImpl peerImpl, List<BgpLSNlri> nlri, List<BgpValueType> pathAttr) throws BgpParseException {
ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
while (listIterator.hasNext()) {
BgpLSNlri nlriInfo = listIterator.next();
if (nlriInfo instanceof BgpNodeLSNlriVer4) {
PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr);
if (!((BgpNodeLSNlriVer4) nlriInfo).isVpnPresent()) {
adjRib.add(nlriInfo, details);
bgplocalRib.add(sessionInfo(), nlriInfo, details);
} else {
vpnAdjRib.addVpn(nlriInfo, details, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher());
bgplocalRibVpn.add(sessionInfo(), nlriInfo, details, ((BgpNodeLSNlriVer4) nlriInfo).getRouteDistinguisher());
}
} else if (nlriInfo instanceof BgpLinkLsNlriVer4) {
PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr);
if (!((BgpLinkLsNlriVer4) nlriInfo).isVpnPresent()) {
adjRib.add(nlriInfo, details);
bgplocalRib.add(sessionInfo(), nlriInfo, details);
} else {
vpnAdjRib.addVpn(nlriInfo, details, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher());
bgplocalRibVpn.add(sessionInfo(), nlriInfo, details, ((BgpLinkLsNlriVer4) nlriInfo).getRouteDistinguisher());
}
} else if (nlriInfo instanceof BgpPrefixIPv4LSNlriVer4) {
PathAttrNlriDetails details = setPathAttrDetails(nlriInfo, pathAttr);
if (!((BgpPrefixIPv4LSNlriVer4) nlriInfo).isVpnPresent()) {
adjRib.add(nlriInfo, details);
bgplocalRib.add(sessionInfo(), nlriInfo, details);
} else {
vpnAdjRib.addVpn(nlriInfo, details, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher());
bgplocalRibVpn.add(sessionInfo(), nlriInfo, details, ((BgpPrefixIPv4LSNlriVer4) nlriInfo).getRouteDistinguisher());
}
}
}
}
use of org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4 in project onos by opennetworkinglab.
the class BgpUpdateMsgTest method bgpUpdateMessageTest18.
/**
* This test case checks update message with node NLRI.
*/
@Test
public void bgpUpdateMessageTest18() 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 len
(byte) 0xff, // withdrawn len
(byte) 0xff, // withdrawn len
0x00, // withdrawn len
0x60, // withdrawn len
0x02, // withdrawn len
0x00, // withdrawn len
0x00, // path attribute len
0x00, // path attribute len
0x49, // 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, // mpreach with safi = 71
(byte) 0x80, // mpreach with safi = 71
0x0e, // mpreach with safi = 71
0x34, // mpreach with safi = 71
0x40, // mpreach with safi = 71
0x04, // mpreach with safi = 71
0x47, // nexthop
0x04, // nexthop
0x04, // nexthop
0x00, // nexthop
0x00, // nexthop
0x01, // reserved
0x00, 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) 96));
BgpValueType testPathAttribute;
Origin origin;
AsPath asPath;
Med med;
MpReachNlri mpReach;
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();
mpReach = (MpReachNlri) testPathAttribute;
assertThat(mpReach.mpReachNlriLen(), is((int) 52));
assertThat(mpReach.getType(), is((short) 14));
List<BgpLSNlri> testMpReachNlri = new LinkedList<>();
testMpReachNlri = mpReach.mpReachNlri();
ListIterator<BgpLSNlri> list1 = testMpReachNlri.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));
}
Aggregations