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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations