use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpChannelHandler method asNumberValidation.
/**
* AS Number Validation.
*
* @param h channel Handler
* @param openMsg open message
* @return true or false
*/
private boolean asNumberValidation(BgpChannelHandler h, BgpOpenMsg openMsg) {
log.debug("AS number validation");
int capAsNum = 0;
boolean isFourOctetCapabilityExits = false;
BgpPeerCfg peerCfg = h.bgpconfig.displayPeers(peerAddr);
List<BgpValueType> capabilityTlv = openMsg.getCapabilityTlv();
ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();
while (listIterator.hasNext()) {
BgpValueType tlv = listIterator.next();
if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) {
isFourOctetCapabilityExits = true;
capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt();
}
}
if (peerCfg.getAsNumber() > MAX_AS2_NUM) {
if (openMsg.getAsNumber() != AS_TRANS) {
return false;
}
if (!isFourOctetCapabilityExits) {
return false;
}
if (peerCfg.getAsNumber() != capAsNum) {
return false;
}
isIbgpSession = peerCfg.getIsIBgp();
if (isIbgpSession) {
// IBGP - AS number should be same for Peer and local if it is IBGP
if (h.bgpconfig.getAsNumber() != capAsNum) {
return false;
}
}
} else {
if (openMsg.getAsNumber() != peerCfg.getAsNumber()) {
return false;
}
if (isFourOctetCapabilityExits) {
if (capAsNum != peerCfg.getAsNumber()) {
return false;
}
}
isIbgpSession = peerCfg.getIsIBgp();
if (isIbgpSession) {
// IBGP - AS number should be same for Peer and local if it is IBGP
if (openMsg.getAsNumber() != h.bgpconfig.getAsNumber()) {
return false;
}
}
}
return true;
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage2.
/**
* Peer1 has Node NLRI (MpReach) and Peer2 has Node NLRI with same MpReach and MpUnReach.
*/
@Test
public void testBgpUpdateMessage2() 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);
peer2.peerChannelHandler.capabilityTlv.add(tempTlv1);
Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.95", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.95"));
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 contains specified key
assertThat(adj.nodeTree().containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
// In Local-RIB, nodeTree should contains 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.70", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer2
bgpId = new BgpId(IpAddress.valueOf("127.0.0.70"));
peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
TimeUnit.MILLISECONDS.sleep(200);
adj = peer.adjRib();
// In Adj-RIB, nodetree should be empty
assertThat(adj.nodeTree().isEmpty(), is(true));
// Disconnect peer1
channel.disconnect();
channel.close();
obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
TimeUnit.MILLISECONDS.sleep(200);
// In Local-RIB, nodetree should be empty
assertThat(obj.nodeTree().isEmpty(), is(true));
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage7.
/**
* Peer1 has Node NLRI (MpReach) and peer2 has Node NLRI with same MpReach and MpUnReach with IsIsNonPseudonode.
*/
@Test
public void testBgpUpdateMessage7() 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);
Channel channel = peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.91", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.91"));
BgpPeerImpl peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
LinkedList<BgpValueType> subTlvs = new LinkedList<>();
LinkedList<BgpValueType> subTlvs1 = new LinkedList<>();
BgpValueType tlv = null;
tlv = AutonomousSystemTlv.of(2478);
subTlvs.add(tlv);
tlv = BgpLSIdentifierTlv.of(33686018);
subTlvs.add(tlv);
subTlvs1.add(tlv);
NodeDescriptors nodeDes = new NodeDescriptors(subTlvs, (short) 0x10, (short) 256);
BgpNodeLSIdentifier key = new BgpNodeLSIdentifier(nodeDes);
AdjRibIn adj = peer.adjRib();
// In Adj-RIB, nodeTree should contains specified key
assertThat(adj.nodeTree().containsKey(key), is(true));
BgpLocalRibImpl obj = (BgpLocalRibImpl) bgpControllerImpl.bgpLocalRib();
// In Local-RIB, nodeTree should contains 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.90", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer2
bgpId = new BgpId(IpAddress.valueOf("127.0.0.90"));
peer = (BgpPeerImpl) bgpControllerImpl.getPeer(bgpId);
tlv = AutonomousSystemTlv.of(2222);
subTlvs1.add(tlv);
byte[] isoNodeID = new byte[] { 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58 };
tlv = IsIsNonPseudonode.of(isoNodeID);
subTlvs1.add(tlv);
nodeDes = new NodeDescriptors(subTlvs1, (short) 0x1a, (short) 256);
key = new BgpNodeLSIdentifier(nodeDes);
adj = peer.adjRib();
// In Adj-RIB, nodeTree should contains specified key
log.info("key " + key.toString());
log.info("adj.nodeTree() " + adj.nodeTree().toString());
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 contains specified key
assertThat(obj.nodeTree().containsKey(key), is(true));
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpSelectionAlgoTest method selectionAlgoTest3.
/**
* firstPathAttribute and secondPathAttribute has same AS value
* and firstPathAttribute has shortest Origin value than secondPathAttribute.
*/
@Test
public void selectionAlgoTest3() throws BgpParseException {
byte[] peerIp = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
BgpValueType pathAttribute1;
byte[] origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(origin);
pathAttribute1 = Origin.read(buffer);
pathAttributes1.add(pathAttribute1);
byte[] asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
buffer.writeBytes(asPath);
pathAttribute1 = AsPath.read(buffer);
pathAttributes1.add(pathAttribute1);
IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
int bgpId = 168427777;
short locRibAsNum = 100;
boolean isIbgp = false;
PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
attrList1.setIdentifier(0);
attrList1.setPathAttribute(pathAttributes1);
attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList1);
peerIp = new byte[] { 0x0b, 0x0b, 0x0b, 0x0b };
LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
BgpValueType pathAttribute2;
origin = new byte[] { 0x40, 0x01, 0x01, 0x02 };
buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(origin);
pathAttribute2 = Origin.read(buffer);
pathAttributes2.add(pathAttribute2);
asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
buffer.writeBytes(asPath);
pathAttribute2 = AsPath.read(buffer);
pathAttributes2.add(pathAttribute2);
ipAddress = IpAddress.valueOf(Version.INET, peerIp);
bgpId = 536936448;
locRibAsNum = 200;
isIbgp = true;
PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
attrList2.setIdentifier(0);
attrList2.setPathAttribute(pathAttributes2);
attrList2.setProtocolID(ProtocolType.OSPF_V2);
PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList2);
BgpSelectionAlgo algo = new BgpSelectionAlgo();
int result = algo.compare(list1, list2);
assertThat(result, is(1));
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpSelectionAlgoTest method selectionAlgoTest2.
/**
* firstPathAttribute has 1 AS count and secondPathAttribute has 2 AS count
* and firstPathAttribute has shortest Origin value than secondPathAttribute.
*/
@Test
public void selectionAlgoTest2() throws BgpParseException {
byte[] peerIp = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
LinkedList<BgpValueType> pathAttributes1 = new LinkedList<>();
BgpValueType pathAttribute1;
byte[] origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(origin);
pathAttribute1 = Origin.read(buffer);
pathAttributes1.add(pathAttribute1);
byte[] asPath = new byte[] { 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9 };
buffer.writeBytes(asPath);
pathAttribute1 = AsPath.read(buffer);
pathAttributes1.add(pathAttribute1);
IpAddress ipAddress = IpAddress.valueOf(Version.INET, peerIp);
int bgpId = 168427777;
short locRibAsNum = 100;
boolean isIbgp = false;
PathAttrNlriDetails attrList1 = new PathAttrNlriDetails();
attrList1.setIdentifier(0);
attrList1.setPathAttribute(pathAttributes1);
attrList1.setProtocolID(ProtocolType.ISIS_LEVEL_ONE);
PathAttrNlriDetailsLocalRib list1 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList1);
peerIp = new byte[] { 0x0b, 0x0b, 0x0b, 0x0b };
LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
BgpValueType pathAttribute2;
origin = new byte[] { 0x40, 0x01, 0x01, 0x02 };
buffer = ChannelBuffers.dynamicBuffer();
buffer.writeBytes(origin);
pathAttribute2 = Origin.read(buffer);
pathAttributes2.add(pathAttribute2);
asPath = new byte[] { 0x40, 0x02, 0x08, 0x02, 0x01, (byte) 0xfd, (byte) 0xea, 0x02, 0x01, (byte) 0xfd, (byte) 0xea };
buffer.writeBytes(asPath);
pathAttribute2 = AsPath.read(buffer);
pathAttributes2.add(pathAttribute2);
ipAddress = IpAddress.valueOf(Version.INET, peerIp);
bgpId = 536936448;
locRibAsNum = 200;
isIbgp = true;
PathAttrNlriDetails attrList2 = new PathAttrNlriDetails();
attrList2.setIdentifier(0);
attrList2.setPathAttribute(pathAttributes2);
attrList2.setProtocolID(ProtocolType.OSPF_V2);
PathAttrNlriDetailsLocalRib list2 = new PathAttrNlriDetailsLocalRib(ipAddress, bgpId, locRibAsNum, isIbgp, attrList2);
BgpSelectionAlgo algo = new BgpSelectionAlgo();
int result = algo.compare(list1, list2);
assertThat(result, is(-1));
}
Aggregations