use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpControllerImplTest method bgpOpenMessageTest7.
@Test
public void bgpOpenMessageTest7() throws InterruptedException {
// Open message with both LS capability and as4 capability
short afi = 16388;
byte res = 0;
byte safi = 71;
peer1.peerChannelHandler.asNumber = 200;
peer1.peerChannelHandler.version = 4;
peer1.peerChannelHandler.holdTime = 120;
peer1.peerChannelHandler.isLargeAsCapabilitySet = true;
bgpControllerImpl.getConfig().setLargeASCapability(true);
BgpValueType tempTlv = new FourOctetAsNumCapabilityTlv(200);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv);
bgpControllerImpl.getConfig().setLsCapability(true);
BgpValueType tempTlv1 = new MultiProtocolExtnCapabilityTlv(afi, res, safi);
peer1.peerChannelHandler.capabilityTlv.add(tempTlv1);
peer1.connect(connectToSocket);
boolean result;
result = peer1.peerFrameDecoder.receivedOpenMessageLatch.await(MESSAGE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertThat(result, is(true));
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpControllerImplTest method testBgpUpdateMessage1.
/**
* Peer1 has Node NLRI (MpReach).
*/
@Test
public void testBgpUpdateMessage1() 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);
peer1.connectFrom(connectToSocket, new InetSocketAddress("127.0.0.9", 0));
TimeUnit.MILLISECONDS.sleep(1000);
// Get peer1
BgpId bgpId = new BgpId(IpAddress.valueOf("127.0.0.9"));
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);
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));
}
use of org.onosproject.bgpio.types.BgpValueType in project onos by opennetworkinglab.
the class BgpSelectionAlgoTest method selectionAlgoTest4.
/**
* firstPathAttribute has lowest med than secondPathAttribute.
*/
@Test
public void selectionAlgoTest4() 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[] med = new byte[] { (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00 };
buffer.writeBytes(med);
pathAttribute1 = Med.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);
med = new byte[] { (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x01 };
buffer.writeBytes(med);
pathAttribute2 = Med.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 selectionAlgoTest8.
/**
* secondPathAttribute has lowest peer address than firstPathAttribute.
*/
@Test
public void selectionAlgoTest8() throws BgpParseException {
byte[] peerIp = new byte[] { 0x0b, 0x0b, 0x0b, 0x0b };
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);
// A0A0A00
Integer bgpId = 168430080;
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[] { 0x0a, 0x0a, 0x0a, 0x0a };
LinkedList<BgpValueType> pathAttributes2 = new LinkedList<>();
BgpValueType pathAttribute2;
origin = new byte[] { 0x40, 0x01, 0x01, 0x00 };
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);
// A0A0A00
bgpId = 168430080;
locRibAsNum = 200;
isIbgp = false;
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 selectionAlgoTest7.
/**
* firstPathAttribute has lower BGPID than secondPathAttribute.
*/
@Test
public void selectionAlgoTest7() 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);
// A0A0A00
Integer bgpId = 168430080;
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, 0x00 };
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);
// B0A0A00
bgpId = 185207296;
locRibAsNum = 200;
isIbgp = false;
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