use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.
the class SalToOfSetNwDstActionV10Case method process.
@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetNwDstActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
final ActionBuilder builder = new ActionBuilder();
final Address address = source.getSetNwDstAction().getAddress();
if (address instanceof Ipv4) {
// FIXME use of substring should be removed and OF models should distinguish where
// FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
Ipv4Address result = new Ipv4Address(ipAddress);
SetNwDstCaseBuilder setNwDstCaseBuilder = new SetNwDstCaseBuilder();
SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder();
setNwDstActionBuilder.setIpAddress(result);
setNwDstCaseBuilder.setSetNwDstAction(setNwDstActionBuilder.build());
builder.setActionChoice(setNwDstCaseBuilder.build());
} else {
throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
}
return Optional.of(builder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.
the class SalToOfSetNwSrcActionV10Case method process.
@Nonnull
@Override
public Optional<Action> process(@Nonnull final SetNwSrcActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
final ActionBuilder builder = new ActionBuilder();
final Address address = source.getSetNwSrcAction().getAddress();
if (address instanceof Ipv4) {
// FIXME use of substring should be removed and OF models should distinguish where
// FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask)
String ipAddress = ((Ipv4) address).getIpv4Address().getValue();
ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
Ipv4Address result = new Ipv4Address(ipAddress);
SetNwSrcCaseBuilder nwSrcCaseBuilder = new SetNwSrcCaseBuilder();
SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder();
nwSrcBuilder.setIpAddress(new Ipv4Address(result));
nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build());
builder.setActionChoice(nwSrcCaseBuilder.build());
} else {
throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName());
}
return Optional.of(builder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.
the class MatchV10Convertor method convertL3Ipv4SrcMatch.
/**
* Method splits the IP address and its mask and set their respective values in MatchV10Builder instance.
* Wildcard value of the IP mask will be determined by Openflow java encoding library.
*
* @param matchBuilder match builder
* @param ipv4 ip v4 match
*/
private static void convertL3Ipv4SrcMatch(final MatchV10Builder matchBuilder, final Ipv4Match ipv4) {
if (ipv4.getIpv4Source() != null) {
Iterator<String> addressParts = IpConversionUtil.PREFIX_SPLITTER.split(ipv4.getIpv4Source().getValue()).iterator();
Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
int prefix = buildPrefix(addressParts);
matchBuilder.setNwSrc(ipv4Address);
matchBuilder.setNwSrcMask((short) prefix);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.
the class SetNwSrcActionSerializerTest method testSerialize.
@Test
public void testSerialize() throws Exception {
final Ipv4 address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("192.168.76.2/32")).build();
final Action action = new SetNwSrcActionCaseBuilder().setSetNwSrcAction(new SetNwSrcActionBuilder().setAddress(address).build()).build();
assertAction(action, out -> {
byte[] addressBytes = new byte[4];
out.readBytes(addressBytes);
assertArrayEquals(addressBytes, new byte[] { (byte) 192, (byte) 168, 76, 2 });
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv4._case.Ipv4 in project netvirt by opendaylight.
the class ElanUtils method getSourceIpAddress.
public Optional<IpAddress> getSourceIpAddress(Ethernet ethernet) {
Optional<IpAddress> srcIpAddress = Optional.empty();
if (ethernet.getPayload() == null) {
return srcIpAddress;
}
byte[] ipAddrBytes = null;
if (ethernet.getPayload() instanceof IPv4) {
IPv4 ipv4 = (IPv4) ethernet.getPayload();
ipAddrBytes = Ints.toByteArray(ipv4.getSourceAddress());
} else if (ethernet.getPayload() instanceof ARP) {
ipAddrBytes = ((ARP) ethernet.getPayload()).getSenderProtocolAddress();
}
if (ipAddrBytes != null) {
String ipAddr = NWUtil.toStringIpAddress(ipAddrBytes);
return Optional.of(IpAddressBuilder.getDefaultInstance(ipAddr));
}
return srcIpAddress;
}
Aggregations