Search in sources :

Example 61 with Ip4Address

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

the class NextHop method read.

/**
 * Reads from ChannelBuffer and parses NextHop.
 *
 * @param cb ChannelBuffer
 * @return object of NextHop
 * @throws BgpParseException while parsing nexthop attribute
 */
public static NextHop read(ChannelBuffer cb) throws BgpParseException {
    Ip4Address nextHop;
    ChannelBuffer tempCb = cb.copy();
    Validation parseFlags = Validation.parseAttributeHeader(cb);
    if (cb.readableBytes() < parseFlags.getLength()) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength());
    }
    int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }
    InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb);
    if (ipAddress.isMulticastAddress()) {
        throw new BgpParseException("Multicast address is not supported");
    }
    nextHop = Ip4Address.valueOf(ipAddress);
    return new NextHop(nextHop);
}
Also used : Validation(org.onosproject.bgpio.util.Validation) BgpParseException(org.onosproject.bgpio.exceptions.BgpParseException) Ip4Address(org.onlab.packet.Ip4Address) InetAddress(java.net.InetAddress) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 62 with Ip4Address

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

the class BgpPrefixAttrOspfFwdAddr method read.

/**
 * Reads the OSPF Forwarding Address.
 *
 * @param cb ChannelBuffer
 * @return object of BgpPrefixAttrOSPFFwdAddr
 * @throws BgpParseException while parsing BgpPrefixAttrOspfFwdAddr
 */
public static BgpPrefixAttrOspfFwdAddr read(ChannelBuffer cb) throws BgpParseException {
    short lsAttrLength;
    byte[] ipBytes;
    Ip4Address ip4RouterId = null;
    Ip6Address ip6RouterId = null;
    lsAttrLength = cb.readShort();
    ipBytes = new byte[lsAttrLength];
    if ((cb.readableBytes() < lsAttrLength)) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength);
    }
    cb.readBytes(ipBytes);
    if (IPV4_LEN == lsAttrLength) {
        ip4RouterId = Ip4Address.valueOf(ipBytes);
    } else if (IPV6_LEN == lsAttrLength) {
        ip6RouterId = Ip6Address.valueOf(ipBytes);
    }
    return BgpPrefixAttrOspfFwdAddr.of(lsAttrLength, ip4RouterId, ip6RouterId);
}
Also used : Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address)

Example 63 with Ip4Address

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

the class FlowModBuilderVer10 method buildL3Modification.

private OFAction buildL3Modification(Instruction i) {
    L3ModificationInstruction l3m = (L3ModificationInstruction) i;
    ModIPInstruction ip;
    Ip4Address ip4;
    switch(l3m.subtype()) {
        case IPV4_SRC:
            ip = (ModIPInstruction) i;
            ip4 = ip.ip().getIp4Address();
            return factory().actions().setNwSrc(IPv4Address.of(ip4.toInt()));
        case IPV4_DST:
            ip = (ModIPInstruction) i;
            ip4 = ip.ip().getIp4Address();
            return factory().actions().setNwDst(IPv4Address.of(ip4.toInt()));
        default:
            log.warn("Unimplemented action type {}.", l3m.subtype());
            break;
    }
    return null;
}
Also used : L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Ip4Address(org.onlab.packet.Ip4Address) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction)

Example 64 with Ip4Address

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

the class FlowModBuilderVer13 method buildL3Modification.

protected OFAction buildL3Modification(Instruction i) {
    L3ModificationInstruction l3m = (L3ModificationInstruction) i;
    ModIPInstruction ip;
    Ip4Address ip4;
    Ip6Address ip6;
    OFOxm<?> oxm = null;
    switch(l3m.subtype()) {
        case IPV4_SRC:
            ip = (ModIPInstruction) i;
            ip4 = ip.ip().getIp4Address();
            oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
            break;
        case IPV4_DST:
            ip = (ModIPInstruction) i;
            ip4 = ip.ip().getIp4Address();
            oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
            break;
        case IP_DSCP:
            L3ModificationInstruction.ModDscpInstruction dscp = (L3ModificationInstruction.ModDscpInstruction) i;
            IpDscp ipDscp = IpDscp.of(dscp.dscp());
            oxm = factory().oxms().ipDscp(ipDscp);
            break;
        case IPV6_SRC:
            ip = (ModIPInstruction) i;
            ip6 = ip.ip().getIp6Address();
            oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
            break;
        case IPV6_DST:
            ip = (ModIPInstruction) i;
            ip6 = ip.ip().getIp6Address();
            oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
            break;
        case IPV6_FLABEL:
            ModIPv6FlowLabelInstruction flowLabelInstruction = (ModIPv6FlowLabelInstruction) i;
            int flowLabel = flowLabelInstruction.flowLabel();
            oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
            break;
        case ARP_SPA:
            ModArpIPInstruction sAip = (ModArpIPInstruction) i;
            ip4 = sAip.ip().getIp4Address();
            oxm = factory().oxms().arpSpa(IPv4Address.of(ip4.toInt()));
            break;
        case ARP_SHA:
            ModArpEthInstruction sAei = (ModArpEthInstruction) i;
            oxm = factory().oxms().arpSha(MacAddress.of(sAei.mac().toLong()));
            break;
        case ARP_TPA:
            ModArpIPInstruction dAip = (ModArpIPInstruction) i;
            ip4 = dAip.ip().getIp4Address();
            oxm = factory().oxms().arpTpa(IPv4Address.of(ip4.toInt()));
            break;
        case ARP_THA:
            ModArpEthInstruction dAei = (ModArpEthInstruction) i;
            oxm = factory().oxms().arpTha(MacAddress.of(dAei.mac().toLong()));
            break;
        case ARP_OP:
            ModArpOpInstruction oi = (ModArpOpInstruction) i;
            oxm = factory().oxms().arpOp(ArpOpcode.of((int) oi.op()));
            break;
        case DEC_TTL:
            return factory().actions().decNwTtl();
        case TTL_IN:
            return factory().actions().copyTtlIn();
        case TTL_OUT:
            return factory().actions().copyTtlOut();
        default:
            log.warn("Unimplemented action type {}.", l3m.subtype());
            break;
    }
    if (oxm != null) {
        return factory().actions().buildSetField().setField(oxm).build();
    }
    return null;
}
Also used : ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Ip4Address(org.onlab.packet.Ip4Address) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction) Ip6Address(org.onlab.packet.Ip6Address) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) IpDscp(org.projectfloodlight.openflow.types.IpDscp)

Example 65 with Ip4Address

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

the class NiciraSetTunnelDstCodec method decode.

@Override
public NiciraSetTunnelDst decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    // parse tunnel destination IP address
    String dstIp = nullIsIllegal(json.get(TUNNEL_DST), TUNNEL_DST + MISSING_MEMBER_MESSAGE).asText();
    Ip4Address tunnelDst = Ip4Address.valueOf(dstIp);
    return new NiciraSetTunnelDst(tunnelDst);
}
Also used : NiciraSetTunnelDst(org.onosproject.driver.extensions.NiciraSetTunnelDst) Ip4Address(org.onlab.packet.Ip4Address)

Aggregations

Ip4Address (org.onlab.packet.Ip4Address)98 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