Search in sources :

Example 11 with Ip4Prefix

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)));
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) ArrayList(java.util.ArrayList) Ip4Prefix(org.onlab.packet.Ip4Prefix) Test(org.junit.Test)

Example 12 with Ip4Prefix

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);
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) ArrayList(java.util.ArrayList) Ip4Prefix(org.onlab.packet.Ip4Prefix) Test(org.junit.Test)

Example 13 with Ip4Prefix

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));
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) ArrayList(java.util.ArrayList) Ip4Prefix(org.onlab.packet.Ip4Prefix) Test(org.junit.Test)

Example 14 with Ip4Prefix

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;
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) ArrayList(java.util.ArrayList) Ip4Prefix(org.onlab.packet.Ip4Prefix)

Example 15 with Ip4Prefix

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));
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) ArrayList(java.util.ArrayList) Ip4Prefix(org.onlab.packet.Ip4Prefix) Test(org.junit.Test)

Aggregations

Ip4Prefix (org.onlab.packet.Ip4Prefix)32 Ip4Address (org.onlab.packet.Ip4Address)20 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)11 Ip6Prefix (org.onlab.packet.Ip6Prefix)10 Ip6Address (org.onlab.packet.Ip6Address)6 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4 LinkedList (java.util.LinkedList)2 Up4AdminService (org.omecproject.up4.impl.Up4AdminService)2 OduSignalId (org.onosproject.net.OduSignalId)2 UpfInterface (org.onosproject.net.behaviour.upf.UpfInterface)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 OFOxm (org.projectfloodlight.openflow.protocol.oxm.OFOxm)2 CircuitSignalID (org.projectfloodlight.openflow.types.CircuitSignalID)2 IPv4Address (org.projectfloodlight.openflow.types.IPv4Address)2 IPv6Address (org.projectfloodlight.openflow.types.IPv6Address)2 OFVlanVidMatch (org.projectfloodlight.openflow.types.OFVlanVidMatch)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1