Search in sources :

Example 21 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class DefaultNeighbourMessageActionsTest method reply.

@Test
public void reply() throws Exception {
    Ethernet request = NeighbourTestUtils.createArpRequest(IP1);
    Ip4Address ip4Address = INTF1.ipAddressesList().get(0).ipAddress().getIp4Address();
    Ethernet response = ARP.buildArpReply(ip4Address, MAC2, request);
    packetService.emit(outbound(response, CP1));
    expectLastCall().once();
    replay(packetService);
    actions.reply(createContext(request, CP1, null), MAC2);
    verify(packetService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) Ip4Address(org.onlab.packet.Ip4Address) Test(org.junit.Test)

Example 22 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class OspfPseudonode method read.

/**
 * Reads the channel buffer and returns object of OSPFPseudonode.
 *
 * @param cb ChannelBuffer
 * @return object of OSPFPseudonode
 */
public static OspfPseudonode read(ChannelBuffer cb) {
    int routerID = cb.readInt();
    Ip4Address drInterface = Ip4Address.valueOf(cb.readInt());
    return OspfPseudonode.of(routerID, drInterface);
}
Also used : Ip4Address(org.onlab.packet.Ip4Address)

Example 23 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class BgpAttrRouterIdV4 method read.

/**
 * Reads the IPv4 Router-ID.
 *
 * @param cb ChannelBuffer
 * @param sType tag type
 * @return object of BgpAttrRouterIdV4
 * @throws BgpParseException while parsing BgpAttrRouterIdV4
 */
public static BgpAttrRouterIdV4 read(ChannelBuffer cb, short sType) throws BgpParseException {
    short lsAttrLength = cb.readShort();
    if ((lsAttrLength != 4) || (cb.readableBytes() < lsAttrLength)) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength);
    }
    byte[] ipBytes = new byte[lsAttrLength];
    cb.readBytes(ipBytes, 0, lsAttrLength);
    Ip4Address ip4RouterId = Ip4Address.valueOf(ipBytes);
    return BgpAttrRouterIdV4.of(ip4RouterId, sType);
}
Also used : Ip4Address(org.onlab.packet.Ip4Address)

Example 24 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class IPv4AddressTlv method read.

/**
 * Reads the channel buffer and returns object of IPv4AddressTlv.
 *
 * @param cb channelBuffer
 * @param type address type
 * @return object of IPv4AddressTlv
 * @throws BgpParseException while parsing IPv4AddressTlv
 */
public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BgpParseException {
    InetAddress ipAddress = Validation.toInetAddress(LENGTH, cb);
    if (ipAddress.isMulticastAddress()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null);
    }
    Ip4Address address = Ip4Address.valueOf(ipAddress);
    return IPv4AddressTlv.of(address, type);
}
Also used : BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) Ip4Address(org.onlab.packet.Ip4Address) InetAddress(java.net.InetAddress)

Example 25 with Ip4Address

use of org.onlab.packet.Ip4Address in project onos by opennetworkinglab.

the class BgpRouteEntryTest method testGetFields.

/**
 * Tests getting the fields of a BGP route entry.
 */
@Test
public void testGetFields() {
    // Create the fields to compare against
    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;
    // Generate the entry to test
    BgpRouteEntry bgpRouteEntry = generateBgpRouteEntry();
    assertThat(bgpRouteEntry.prefix(), is(prefix));
    assertThat(bgpRouteEntry.nextHop(), is(nextHop));
    assertThat(bgpRouteEntry.getBgpSession(), is(bgpSession));
    assertThat(bgpRouteEntry.getOrigin(), is(origin));
    assertThat(bgpRouteEntry.getAsPath(), is(asPath));
    assertThat(bgpRouteEntry.getLocalPref(), is(localPref));
    assertThat(bgpRouteEntry.getMultiExitDisc(), is(multiExitDisc));
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) ArrayList(java.util.ArrayList) Ip4Prefix(org.onlab.packet.Ip4Prefix) Test(org.junit.Test)

Aggregations

Ip4Address (org.onlab.packet.Ip4Address)96 Test (org.junit.Test)29 Ip4Prefix (org.onlab.packet.Ip4Prefix)20 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)15 MacAddress (org.onlab.packet.MacAddress)15 ArrayList (java.util.ArrayList)14 Ip6Address (org.onlab.packet.Ip6Address)14 IpAddress (org.onlab.packet.IpAddress)13 LinkedList (java.util.LinkedList)12 Ethernet (org.onlab.packet.Ethernet)12 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)12 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)12 AsPath (org.onosproject.bgpio.types.AsPath)12 BgpHeader (org.onosproject.bgpio.types.BgpHeader)12 BgpValueType (org.onosproject.bgpio.types.BgpValueType)12 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)12 Med (org.onosproject.bgpio.types.Med)12 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)12 Origin (org.onosproject.bgpio.types.Origin)12 OriginType (org.onosproject.bgpio.types.Origin.OriginType)12