use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4 in project bgpcep by opendaylight.
the class GenericConditionPolicyHandler method createPrefixes.
private static List<IpPrefix> createPrefixes(final Prefix prefixContainer) {
final IpPrefix prefix = prefixContainer.getIpPrefix();
if (prefixContainer.getMasklengthRange().equals(EXACT)) {
return Collections.singletonList(prefix);
}
final String[] range = prefixContainer.getMasklengthRange().split("\\..");
boolean ipv4 = false;
final String prefixString;
if (prefix.getIpv4Prefix() != null) {
prefixString = prefix.getIpv4Prefix().getValue();
ipv4 = true;
} else {
prefixString = prefix.getIpv6Prefix().getValue();
}
int from = Integer.parseInt(range[0]);
final List<IpPrefix> prefixes = new ArrayList<>();
while (from <= Integer.parseInt(range[1])) {
final String prefixVal = StringUtils.replacePattern(prefixString, "[/][0-9]+", "/" + Integer.toString(from));
if (ipv4) {
prefixes.add(new IpPrefix(new Ipv4Prefix(prefixVal)));
} else {
prefixes.add(new IpPrefix(new Ipv6Prefix(prefixVal)));
}
from++;
}
return prefixes;
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4 in project bgpcep by opendaylight.
the class UriBuilderTest method test.
@Test
public void test() {
final LinkstateRouteBuilder routeB = new LinkstateRouteBuilder().setProtocolId(ProtocolId.Direct).setIdentifier(new Identifier(BigInteger.TEN));
final UriBuilder a = new UriBuilder(routeB.build());
assertEquals("bgpls://Direct:10/", a.toString());
routeB.setDistinguisher(new RouteDistinguisher(BigInteger.ONE));
final UriBuilder b = new UriBuilder(routeB.build());
assertEquals("bgpls://1:Direct:10/", b.toString());
final UriBuilder c = new UriBuilder(b, "foo");
assertEquals("bgpls://1:Direct:10/type=foo", c.toString());
a.add("foo", 25L);
assertEquals("bgpls://Direct:10/&foo=25", a.toString());
final LinkCaseBuilder linkB = new LinkCaseBuilder();
linkB.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier("127.0.0.1")).setIpv4NeighborAddress(new Ipv4InterfaceIdentifier("20.20.20.20")).setMultiTopologyId(new TopologyIdentifier(55)).setLinkLocalIdentifier(1L).setLinkRemoteIdentifier(2L).build());
final LocalNodeDescriptorsBuilder nodeB = new LocalNodeDescriptorsBuilder();
nodeB.setAsNumber(new AsNumber(12L)).setDomainId(new DomainIdentifier(15L)).setAreaId(new AreaIdentifier(17L));
nodeB.setCRouterIdentifier(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(22L).build()).build());
linkB.setLocalNodeDescriptors(nodeB.build());
final RemoteNodeDescriptorsBuilder nodeR = new RemoteNodeDescriptorsBuilder();
nodeR.setCRouterIdentifier(new IsisPseudonodeCaseBuilder().setIsisPseudonode(new IsisPseudonodeBuilder().setIsIsRouterIdentifier(new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).setPsn((short) 2).build()).build());
linkB.setRemoteNodeDescriptors(nodeR.build());
c.add(linkB.build());
assertEquals("bgpls://1:Direct:10/type=foo&local-as=12&local-domain=15&local-area=17&local-router=22" + "&remote-router=0102.0304.0506.02&ipv4-iface=127.0.0.1&ipv4-neigh=20.20.20.20&mt=55&local-id=1&" + "remote-id=2", c.toString());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4 in project bgpcep by opendaylight.
the class RouteDistinguisherUtil method parseRouteDistinguisher.
/**
* Parses three types of route distinguisher from given ByteBuf.
*/
public static RouteDistinguisher parseRouteDistinguisher(final ByteBuf buffer) {
Preconditions.checkState(buffer != null && buffer.isReadable(RD_LENGTH), "Cannot read Route Distinguisher from provided buffer.");
final int type = buffer.readUnsignedShort();
final RDType rdType = RDType.valueOf(type);
final StringBuilder routeDistiguisher = new StringBuilder();
switch(rdType) {
case AS_2BYTE:
routeDistiguisher.append(type);
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedShort());
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedInt());
return new RouteDistinguisher(new RdTwoOctetAs(routeDistiguisher.toString()));
case IPV4:
routeDistiguisher.append(Ipv4Util.addressForByteBuf(buffer).getValue());
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedShort());
return new RouteDistinguisher(new RdIpv4(routeDistiguisher.toString()));
case AS_4BYTE:
routeDistiguisher.append(buffer.readUnsignedInt());
routeDistiguisher.append(SEPARATOR);
routeDistiguisher.append(buffer.readUnsignedShort());
return new RouteDistinguisher(new RdAs(routeDistiguisher.toString()));
default:
// in order to get the byte index correct
for (int i = 0; i < 6; i++) {
routeDistiguisher.append("0x").append(Integer.toHexString(buffer.readByte() & 0xFF)).append(" ");
}
LOG.debug("Invalid Route Distinguisher: type={}, rawRouteDistinguisherValue={}", type, routeDistiguisher.toString());
throw new IllegalArgumentException("Invalid Route Distinguisher type " + type);
}
}
Aggregations