use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case in project bgpcep by opendaylight.
the class PCCEndPointIpv4ObjectParserTest method testParseObject.
@Test
public void testParseObject() throws PCEPDeserializerException {
final ObjectHeader header = new ObjectHeaderImpl(false, false);
final ByteBuf bytes = Unpooled.buffer();
bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4AddressNoZone(IP1)));
bytes.writeBytes(Ipv4Util.bytesForAddress(new Ipv4AddressNoZone(IP2)));
final EndpointsObj output = (EndpointsObj) new PCCEndPointIpv4ObjectParser().parseObject(header, bytes);
assertEquals(IP1, ((Ipv4Case) output.getAddressFamily()).getIpv4().getSourceIpv4Address().getValue());
assertEquals(IP2, ((Ipv4Case) output.getAddressFamily()).getIpv4().getDestinationIpv4Address().getValue());
assertFalse(output.getIgnore());
assertFalse(output.getProcessingRule());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case in project bgpcep by opendaylight.
the class PathComputationImpl method getConstraints.
private static PathConstraints getConstraints(final EndpointsObj endpoints, final Bandwidth bandwidth, final ClassType classType, final List<Metrics> metrics, final boolean segmentRouting) {
ConstraintsBuilder ctsBuilder = new ConstraintsBuilder();
Float convert;
/* Set Metrics if any */
if (metrics != null) {
for (Metrics metric : metrics) {
convert = ByteBuffer.wrap(metric.getMetric().getValue().getValue()).getFloat();
final long value = convert.longValue();
/* Skip Metric with value equal to 0 */
if (value == 0) {
continue;
}
switch(metric.getMetric().getMetricType().intValue()) {
case MessagesUtil.IGP_METRIC:
ctsBuilder.setMetric(Uint32.valueOf(value));
break;
case MessagesUtil.TE_METRIC:
ctsBuilder.setTeMetric(Uint32.valueOf(value));
break;
case MessagesUtil.PATH_DELAY:
ctsBuilder.setDelay(new Delay(Uint32.valueOf(value)));
break;
default:
LOG.warn("Metric {} is not handle by Path Computation Constraints", metric);
break;
}
}
}
/* Set Bandwidth and Class Type */
if (bandwidth != null) {
convert = ByteBuffer.wrap(bandwidth.getBandwidth().getValue()).getFloat();
final long value = convert.longValue();
/* Skip Bandwidth with value equal to 0 */
if (value != 0) {
ctsBuilder.setBandwidth(new DecimalBandwidth(BigDecimal.valueOf(value)));
if (classType != null) {
ctsBuilder.setClassType(classType.getClassType().getValue());
}
}
}
/* Set Address Family */
if (endpoints.getAddressFamily() instanceof Ipv4Case) {
ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv4 : AddressFamily.Ipv4);
} else {
ctsBuilder.setAddressFamily(segmentRouting ? AddressFamily.SrIpv6 : AddressFamily.Ipv6);
}
return ctsBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case in project bgpcep by opendaylight.
the class StatefulLSPIdentifierIpv4TlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
checkArgument(tlv instanceof LspIdentifiers, "LspIdentifiersTlv is mandatory.");
final LspIdentifiers lsp = (LspIdentifiers) tlv;
final AddressFamily afi = lsp.getAddressFamily();
final ByteBuf body = Unpooled.buffer();
if (afi.implementedInterface().equals(Ipv6Case.class)) {
new StatefulLSPIdentifierIpv6TlvParser().serializeTlv(tlv, buffer);
}
final Ipv4 ipv4 = ((Ipv4Case) afi).getIpv4();
checkArgument(ipv4.getIpv4TunnelSenderAddress() != null, "Ipv4TunnelSenderAddress is mandatory.");
Ipv4Util.writeIpv4Address(ipv4.getIpv4TunnelSenderAddress(), body);
checkArgument(lsp.getLspId() != null, "LspId is mandatory.");
body.writeShort(lsp.getLspId().getValue().shortValue());
final TunnelId tunnelId = lsp.getTunnelId();
checkArgument(tunnelId != null, "TunnelId is mandatory.");
ByteBufUtils.write(body, tunnelId.getValue());
checkArgument(ipv4.getIpv4ExtendedTunnelId() != null, "Ipv4ExtendedTunnelId is mandatory.");
Ipv4Util.writeIpv4Address(ipv4.getIpv4ExtendedTunnelId(), body);
checkArgument(ipv4.getIpv4TunnelEndpointAddress() != null, "Ipv4TunnelEndpointAddress is mandatory.");
Ipv4Util.writeIpv4Address(ipv4.getIpv4TunnelEndpointAddress(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4Case in project bgpcep by opendaylight.
the class PCEPIpv4UnreachDestinationParser method serializeObject.
public static void serializeObject(final Boolean processing, final Boolean ignore, final Ipv4DestinationCase ipv4Case, final ByteBuf buffer) {
final List<Ipv4AddressNoZone> dest = ipv4Case.getDestinationIpv4Address();
checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH * dest.size());
dest.forEach(ipv4 -> Ipv4Util.writeIpv4Address(ipv4, body));
ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
}
Aggregations