use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.
the class OfToSalIpv4SrcCase method process.
@Override
public Optional<MatchBuilder> process(@Nonnull Ipv4SrcCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final MatchBuilder matchBuilder = data.getMatchBuilder();
final Ipv4MatchBuilder ipv4MatchBuilder = data.getIpv4MatchBuilder();
final Ipv4MatchArbitraryBitMaskBuilder ipv4MatchArbitraryBitMaskBuilder = data.getIpv4MatchArbitraryBitMaskBuilder();
Ipv4Src ipv4Address = source.getIpv4Src();
if (ipv4Address != null) {
byte[] mask = ipv4Address.getMask();
if (mask != null && IpConversionUtil.isArbitraryBitMask(mask)) {
// Needs to convert ipv4dst to ipv4MatchArbitrary.
if (ipv4MatchBuilder.getIpv4Destination() != null) {
Ipv4Prefix ipv4PrefixDestinationAddress = ipv4MatchBuilder.getIpv4Destination();
Ipv4Address ipv4DstAddress = IpConversionUtil.extractIpv4Address(ipv4PrefixDestinationAddress);
DottedQuad dstDottedQuadMask = IpConversionUtil.extractIpv4AddressMask(ipv4PrefixDestinationAddress);
setDstIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, dstDottedQuadMask, ipv4DstAddress.getValue());
}
DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, srcDottedQuadMask, stringIpv4SrcAddress);
matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
} else if (ipv4MatchArbitraryBitMaskBuilder.getIpv4DestinationAddressNoMask() != null) {
/*
Case where destination is of type ipv4MatchArbitraryBitMask already exists in Layer3Match,
source which of type ipv4Match needs to be converted to ipv4MatchArbitraryBitMask.
We convert 36.36.36.0/24 to 36.36.0/255.255.255.0
expected output example:-
<ipv4-destination>36.36.36.0/24</ipv4-destination>
<ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
<ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
after conversion output example:-
<ipv4-destination-address-no-mask>36.36.36.0</ipv4-destination-address-no-mask>
<ipv4-destination-arbitrary-bitmask>255.255.255.0</ipv4-destination-arbitrary-bitmask>
<ipv4-source-address-no-mask>36.36.36.0</ipv4-source-address-no-mask>
<ipv4-source-arbitrary-bitmask>255.0.255.0</ipv4-source-arbitrary-bitmask>
*/
DottedQuad srcDottedQuadMask = IpConversionUtil.createArbitraryBitMask(mask);
String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
setSrcIpv4MatchArbitraryBitMaskBuilderFields(ipv4MatchArbitraryBitMaskBuilder, srcDottedQuadMask, stringIpv4SrcAddress);
matchBuilder.setLayer3Match(ipv4MatchArbitraryBitMaskBuilder.build());
} else {
String stringIpv4SrcAddress = ipv4Address.getIpv4Address().getValue();
setIpv4MatchBuilderFields(ipv4MatchBuilder, mask, stringIpv4SrcAddress);
matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
}
}
return Optional.of(matchBuilder);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project openflowplugin by opendaylight.
the class SalToOfSetNwDstActionCase 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) {
Iterable<String> addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue());
Ipv4Address result = new Ipv4Address(addressParts.iterator().next());
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(Ipv4Dst.class);
Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder();
Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder();
ipv4DstBuilder.setIpv4Address(result);
Integer prefix = IpConversionUtil.extractPrefix(result);
ipv4DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix));
ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build());
matchEntryBuilder.setHasMask(false);
matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build());
List<MatchEntry> matchEntriesList = new ArrayList<>();
matchEntriesList.add(matchEntryBuilder.build());
SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder();
setFieldActionBuilder.setMatchEntry(matchEntriesList);
setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build());
builder.setActionChoice(setFieldCaseBuilder.build());
} else if (address instanceof Ipv6) {
Iterable<String> addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue());
Ipv6Address result = new Ipv6Address(addressParts.iterator().next());
MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder();
matchEntryBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntryBuilder.setOxmMatchField(Ipv6Dst.class);
Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder();
Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder();
ipv6DstBuilder.setIpv6Address(result);
Integer prefix = IpConversionUtil.extractPrefix(result);
ipv6DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix));
ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build());
matchEntryBuilder.setHasMask(false);
matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build());
List<MatchEntry> matchEntriesList = new ArrayList<>();
matchEntriesList.add(matchEntryBuilder.build());
SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder();
setFieldActionBuilder.setMatchEntry(matchEntriesList);
setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build());
builder.setActionChoice(setFieldCaseBuilder.build());
} else {
throw new IllegalArgumentException("Address is not supported: " + address.getClass().getName());
}
return Optional.of(builder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project bgpcep by opendaylight.
the class TableTypeActivatorTest method testActivator.
@Test
public void testActivator() {
final TableTypeActivator tableTypeActivator = new TableTypeActivator();
final SimpleBGPTableTypeRegistryProvider registry = new SimpleBGPTableTypeRegistryProvider();
tableTypeActivator.startBGPTableTypeRegistryProvider(registry);
final Optional<Class<? extends AfiSafiType>> afiSafiType = registry.getAfiSafiType(IPV4);
Assert.assertEquals(IPV4LABELLEDUNICAST.class, afiSafiType.get());
final Optional<Class<? extends AfiSafiType>> afiSafiType2 = registry.getAfiSafiType(IPV6);
Assert.assertEquals(IPV6LABELLEDUNICAST.class, afiSafiType2.get());
final Optional<BgpTableType> tableType = registry.getTableType(IPV4LABELLEDUNICAST.class);
Assert.assertEquals(IPV4, tableType.get());
final Optional<BgpTableType> tableType2 = registry.getTableType(IPV6LABELLEDUNICAST.class);
Assert.assertEquals(IPV6, tableType2.get());
tableTypeActivator.stopBGPTableTypeRegistryProvider();
tableTypeActivator.close();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project bgpcep by opendaylight.
the class LinkAttributesParser method parseLinkAttributes.
/**
* Parse Link Attributes.
*
* @param attributes key is the tlv type and value is the value of the tlv
* @param protocolId to differentiate parsing methods
* @return {@link LinkStateAttribute}
*/
static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
final LinkAttributesBuilder builder = new LinkAttributesBuilder();
final List<SrAdjIds> srAdjIds = new ArrayList<>();
final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
final List<PeerSetSids> peerSetSids = new ArrayList<>();
for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
LOG.trace("Link attribute TLV {}", entry.getKey());
final int key = entry.getKey();
final ByteBuf value = entry.getValue();
switch(key) {
case TlvUtil.LOCAL_IPV4_ROUTER_ID:
builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
break;
case TlvUtil.LOCAL_IPV6_ROUTER_ID:
builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
break;
case REMOTE_IPV4_ROUTER_ID:
builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
break;
case REMOTE_IPV6_ROUTER_ID:
builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
break;
case ADMIN_GROUP:
builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
break;
case MAX_BANDWIDTH:
builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
break;
case MAX_RESERVABLE_BANDWIDTH:
builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
break;
case UNRESERVED_BANDWIDTH:
parseUnreservedBandwidth(value, builder);
break;
case TE_METRIC:
builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
LOG.debug("Parsed Metric {}", builder.getTeMetric());
break;
case LINK_PROTECTION_TYPE:
builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
break;
case MPLS_PROTOCOL:
final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
break;
case METRIC:
// length can 3, 2 or 1
builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
LOG.debug("Parsed Metric {}", builder.getMetric());
break;
case SHARED_RISK_LINK_GROUP:
parseSrlg(value, builder);
break;
case LINK_OPAQUE:
LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
break;
case LINK_NAME:
builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
LOG.debug("Parsed Link Name : {}", builder.getLinkName());
break;
case SR_ADJ_ID:
srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
break;
case SR_LAN_ADJ_ID:
srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
break;
case PEER_NODE_SID_CODE:
builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
break;
case PEER_ADJ_SID_CODE:
builder.setPeerAdjSid(new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
break;
case PEER_SET_SID_CODE:
peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
break;
default:
LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
}
}
if (!srAdjIds.isEmpty()) {
builder.setSrAdjIds(srAdjIds);
}
if (!srLanAdjIds.isEmpty()) {
builder.setSrLanAdjIds(srLanAdjIds);
}
if (!peerSetSids.isEmpty()) {
builder.setPeerSetSids(peerSetSids);
}
LOG.trace("Finished parsing Link Attributes.");
return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project bgpcep by opendaylight.
the class NodeAttributesParser method parseNodeAttributes.
/**
* Parse Node Attributes.
*
* @param attributes key is the tlv type and value is the value of the tlv
* @param protocolId to differentiate parsing methods
* @return {@link LinkStateAttribute}
*/
static LinkStateAttribute parseNodeAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
final List<TopologyIdentifier> topologyMembership = new ArrayList<>();
final List<IsisAreaIdentifier> areaMembership = new ArrayList<>();
final NodeAttributesBuilder builder = new NodeAttributesBuilder();
for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
final int key = entry.getKey();
final ByteBuf value = entry.getValue();
LOG.trace("Node attribute TLV {}", key);
switch(key) {
case TlvUtil.MULTI_TOPOLOGY_ID:
parseTopologyId(topologyMembership, value);
break;
case NODE_FLAG_BITS:
parseNodeFlags(value, builder);
break;
case NODE_OPAQUE:
if (LOG.isDebugEnabled()) {
LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value));
}
break;
case DYNAMIC_HOSTNAME:
builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
LOG.debug("Parsed Node Name {}", builder.getDynamicHostname());
break;
case ISIS_AREA_IDENTIFIER:
final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value));
areaMembership.add(ai);
LOG.debug("Parsed AreaIdentifier {}", ai);
break;
case TlvUtil.LOCAL_IPV4_ROUTER_ID:
final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value));
builder.setIpv4RouterId(ip4);
LOG.debug("Parsed IPv4 Router Identifier {}", ip4);
break;
case TlvUtil.LOCAL_IPV6_ROUTER_ID:
final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value));
builder.setIpv6RouterId(ip6);
LOG.debug("Parsed IPv6 Router Identifier {}", ip6);
break;
case SR_CAPABILITIES:
final SrCapabilities caps = SrNodeAttributesParser.parseSrCapabilities(value, protocolId);
builder.setSrCapabilities(caps);
LOG.debug("Parsed SR Capabilities {}", caps);
break;
case SR_ALGORITHMS:
final SrAlgorithm algs = SrNodeAttributesParser.parseSrAlgorithms(value);
builder.setSrAlgorithm(algs);
LOG.debug("Parsed SR Algorithms {}", algs);
break;
default:
LOG.warn("TLV {} is not a valid node attribute, ignoring it", key);
}
}
LOG.trace("Finished parsing Node Attributes.");
builder.setTopologyIdentifier(topologyMembership);
builder.setIsisAreaId(areaMembership);
return new NodeAttributesCaseBuilder().setNodeAttributes(builder.build()).build();
}
Aggregations