use of org.onlab.packet.Ip4Prefix in project onos by opennetworkinglab.
the class BgpRouteEntryTest method testNonEquality.
/**
* Tests non-equality of {@link BgpRouteEntry}.
*/
@Test
public void testNonEquality() {
BgpRouteEntry bgpRouteEntry1 = generateBgpRouteEntry();
// Setup BGP Route 2
Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
byte origin = BgpConstants.Update.Origin.IGP;
// Setup the AS Path
ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
byte pathSegmentType1 = (byte) BgpConstants.Update.AsPath.AS_SEQUENCE;
ArrayList<Long> segmentAsNumbers1 = new ArrayList<>();
segmentAsNumbers1.add(1L);
segmentAsNumbers1.add(2L);
segmentAsNumbers1.add(3L);
BgpRouteEntry.PathSegment pathSegment1 = new BgpRouteEntry.PathSegment(pathSegmentType1, segmentAsNumbers1);
pathSegments.add(pathSegment1);
//
byte pathSegmentType2 = (byte) BgpConstants.Update.AsPath.AS_SET;
ArrayList<Long> segmentAsNumbers2 = new ArrayList<>();
segmentAsNumbers2.add(4L);
segmentAsNumbers2.add(5L);
segmentAsNumbers2.add(6L);
BgpRouteEntry.PathSegment pathSegment2 = new BgpRouteEntry.PathSegment(pathSegmentType2, segmentAsNumbers2);
pathSegments.add(pathSegment2);
//
BgpRouteEntry.AsPath asPath = new BgpRouteEntry.AsPath(pathSegments);
//
// Different
long localPref = 500;
long multiExitDisc = 20;
BgpRouteEntry bgpRouteEntry2 = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
assertThat(bgpRouteEntry1, Matchers.is(Matchers.not(bgpRouteEntry2)));
}
use of org.onlab.packet.Ip4Prefix in project onos by opennetworkinglab.
the class BgpRouteEntryTest method testInvalidConstructorNullBgpSession.
/**
* Tests invalid class constructor for null BGP Session.
*/
@Test(expected = NullPointerException.class)
public void testInvalidConstructorNullBgpSession() {
BgpSession bgpSessionNull = null;
Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
byte origin = BgpConstants.Update.Origin.IGP;
// Setup the AS Path
ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
BgpRouteEntry.AsPath asPath = new BgpRouteEntry.AsPath(pathSegments);
//
long localPref = 100;
new BgpRouteEntry(bgpSessionNull, prefix, nextHop, origin, asPath, localPref);
}
use of org.onlab.packet.Ip4Prefix in project onos by opennetworkinglab.
the class BgpRouteEntryTest method testGetNeighborAs.
/**
* Tests getting the BGP Neighbor AS number for a route.
*/
@Test
public void testGetNeighborAs() {
//
// Get neighbor AS for non-local route
//
BgpRouteEntry bgpRouteEntry = generateBgpRouteEntry();
assertThat(bgpRouteEntry.getNeighborAs(), is(1L));
//
// Get neighbor AS for a local route
//
Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
byte origin = BgpConstants.Update.Origin.IGP;
// Setup the AS Path
ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
BgpRouteEntry.AsPath asPath = new BgpRouteEntry.AsPath(pathSegments);
//
long localPref = 100;
long multiExitDisc = 20;
//
bgpRouteEntry = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry.setMultiExitDisc(multiExitDisc);
assertThat(bgpRouteEntry.getNeighborAs(), is(BgpConstants.BGP_AS_0));
}
use of org.onlab.packet.Ip4Prefix in project onos by opennetworkinglab.
the class BgpRouteEntryTest method generateBgpRouteEntry.
/**
* Generates a BGP Route Entry.
*
* @return a generated BGP Route Entry
*/
private BgpRouteEntry generateBgpRouteEntry() {
Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
byte origin = BgpConstants.Update.Origin.IGP;
// Setup the AS Path
ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
byte pathSegmentType1 = (byte) BgpConstants.Update.AsPath.AS_SEQUENCE;
ArrayList<Long> segmentAsNumbers1 = new ArrayList<>();
segmentAsNumbers1.add(1L);
segmentAsNumbers1.add(2L);
segmentAsNumbers1.add(3L);
BgpRouteEntry.PathSegment pathSegment1 = new BgpRouteEntry.PathSegment(pathSegmentType1, segmentAsNumbers1);
pathSegments.add(pathSegment1);
//
byte pathSegmentType2 = (byte) BgpConstants.Update.AsPath.AS_SET;
ArrayList<Long> segmentAsNumbers2 = new ArrayList<>();
segmentAsNumbers2.add(4L);
segmentAsNumbers2.add(5L);
segmentAsNumbers2.add(6L);
BgpRouteEntry.PathSegment pathSegment2 = new BgpRouteEntry.PathSegment(pathSegmentType2, segmentAsNumbers2);
pathSegments.add(pathSegment2);
//
BgpRouteEntry.AsPath asPath = new BgpRouteEntry.AsPath(pathSegments);
//
long localPref = 100;
long multiExitDisc = 20;
BgpRouteEntry bgpRouteEntry = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry.setMultiExitDisc(multiExitDisc);
return bgpRouteEntry;
}
use of org.onlab.packet.Ip4Prefix in project onos by opennetworkinglab.
the class BgpRouteEntryTest method testBgpDecisionProcessComparison.
/**
* Tests the BGP Decision Process comparison of BGP routes.
*/
@Test
public void testBgpDecisionProcessComparison() {
BgpRouteEntry bgpRouteEntry1 = generateBgpRouteEntry();
BgpRouteEntry bgpRouteEntry2 = generateBgpRouteEntry();
//
// Compare two routes that are same
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(true));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(true));
//
// Compare two routes with different LOCAL_PREF
//
Ip4Prefix prefix = Ip4Prefix.valueOf("1.2.3.0/24");
Ip4Address nextHop = Ip4Address.valueOf("5.6.7.8");
byte origin = BgpConstants.Update.Origin.IGP;
// Setup the AS Path
ArrayList<BgpRouteEntry.PathSegment> pathSegments = new ArrayList<>();
byte pathSegmentType1 = (byte) BgpConstants.Update.AsPath.AS_SEQUENCE;
ArrayList<Long> segmentAsNumbers1 = new ArrayList<>();
segmentAsNumbers1.add(1L);
segmentAsNumbers1.add(2L);
segmentAsNumbers1.add(3L);
BgpRouteEntry.PathSegment pathSegment1 = new BgpRouteEntry.PathSegment(pathSegmentType1, segmentAsNumbers1);
pathSegments.add(pathSegment1);
//
byte pathSegmentType2 = (byte) BgpConstants.Update.AsPath.AS_SET;
ArrayList<Long> segmentAsNumbers2 = new ArrayList<>();
segmentAsNumbers2.add(4L);
segmentAsNumbers2.add(5L);
segmentAsNumbers2.add(6L);
BgpRouteEntry.PathSegment pathSegment2 = new BgpRouteEntry.PathSegment(pathSegmentType2, segmentAsNumbers2);
pathSegments.add(pathSegment2);
//
BgpRouteEntry.AsPath asPath = new BgpRouteEntry.AsPath(pathSegments);
//
// Different
long localPref = 50;
long multiExitDisc = 20;
bgpRouteEntry2 = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(true));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(false));
// Restore
localPref = bgpRouteEntry1.getLocalPref();
//
// Compare two routes with different AS_PATH length
//
ArrayList<BgpRouteEntry.PathSegment> pathSegments2 = new ArrayList<>();
pathSegments2.add(pathSegment1);
// Different AS Path
BgpRouteEntry.AsPath asPath2 = new BgpRouteEntry.AsPath(pathSegments2);
bgpRouteEntry2 = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath2, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(false));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(true));
//
// Compare two routes with different ORIGIN
//
// Different
origin = BgpConstants.Update.Origin.EGP;
bgpRouteEntry2 = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(true));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(false));
// Restore
origin = bgpRouteEntry1.getOrigin();
//
// Compare two routes with different MULTI_EXIT_DISC
//
// Different
multiExitDisc = 10;
bgpRouteEntry2 = new BgpRouteEntry(bgpSession, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(true));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(false));
// Restore
multiExitDisc = bgpRouteEntry1.getMultiExitDisc();
//
// Compare two routes with different BGP ID
//
bgpRouteEntry2 = new BgpRouteEntry(bgpSession2, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(true));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(false));
//
// Compare two routes with different BGP address
//
bgpRouteEntry2 = new BgpRouteEntry(bgpSession3, prefix, nextHop, origin, asPath, localPref);
bgpRouteEntry2.setMultiExitDisc(multiExitDisc);
//
assertThat(bgpRouteEntry1.isBetterThan(bgpRouteEntry2), is(true));
assertThat(bgpRouteEntry2.isBetterThan(bgpRouteEntry1), is(false));
}
Aggregations