use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails 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));
}
use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails 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.protocol.linkstate.PathAttrNlriDetails 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.PathAttrNlriDetails 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));
}
use of org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails 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);
}
}
}
}
Aggregations