use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Weight in project netvirt by opendaylight.
the class NAPTSwitchSelector method constructNAPTSwitches.
private Map<Uint64, Integer> constructNAPTSwitches() {
Optional<NaptSwitches> optNaptSwitches = Optional.empty();
try {
optNaptSwitches = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, getNaptSwitchesIdentifier());
} catch (ExecutionException | InterruptedException e) {
LOG.error("constructNAPTSwitches: Exception while reading the NaptSwitches DS", e);
}
Map<Uint64, Integer> switchWeights = new HashMap<>();
if (optNaptSwitches.isPresent()) {
NaptSwitches naptSwitches = optNaptSwitches.get();
for (RouterToNaptSwitch naptSwitch : naptSwitches.nonnullRouterToNaptSwitch().values()) {
Uint64 primarySwitch = naptSwitch.getPrimarySwitchId();
// update weight
Integer weight = switchWeights.get(primarySwitch);
if (weight == null) {
switchWeights.put(primarySwitch, 1);
} else {
switchWeights.put(primarySwitch, ++weight);
}
}
}
return switchWeights;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Weight in project bgpcep by opendaylight.
the class SrLinkAttributesParser method parseEpeAdjacencySegmentIdentifier.
public static EpeAdjSidTlv parseEpeAdjacencySegmentIdentifier(final ByteBuf buffer) {
final Weight weight;
final SidLabelIndex sidValue;
if (buffer.isReadable()) {
final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
weight = new Weight(readUint8(buffer));
buffer.skipBytes(RESERVED);
sidValue = SidLabelIndexParser.parseSidLabelIndexByFlags(Size.forValue(buffer.readableBytes()), buffer, flags.get(VALUE_EPE), flags.get(LOCAL_EPE));
} else {
weight = null;
sidValue = null;
}
return new EpeAdjSidTlv() {
@Override
public Class<EpeAdjSidTlv> implementedInterface() {
return EpeAdjSidTlv.class;
}
@Override
public Weight getWeight() {
return weight;
}
@Override
public SidLabelIndex getSidLabelIndex() {
return sidValue;
}
};
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Weight in project bgpcep by opendaylight.
the class SrLinkAttributesParser method parseLanAdjacencySegmentIdentifier.
public static SrLanAdjIds parseLanAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) {
if (!buffer.isReadable()) {
return new SrLanAdjIdsBuilder().build();
}
final SrLanAdjIdsBuilder srLanAdjIdBuilder = new SrLanAdjIdsBuilder();
final BitArray flags = BitArray.valueOf(buffer, FLAGS_BITS_SIZE);
srLanAdjIdBuilder.setFlags(parseFlags(flags, protocolId));
srLanAdjIdBuilder.setWeight(new Weight(readUint8(buffer)));
buffer.skipBytes(RESERVED);
final boolean isValue;
final boolean isLocal;
switch(protocolId) {
case IsisLevel1:
case IsisLevel2:
isValue = flags.get(VALUE_ISIS);
isLocal = flags.get(LOCAL_ISIS);
srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE)));
break;
case Ospf:
case OspfV3:
isValue = flags.get(VALUE_OSPF);
isLocal = flags.get(LOCAL_OSPF);
srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer));
break;
default:
return null;
}
// length determines a type of next field, which is used for parsing
srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndexByFlags(Size.forValue(buffer.readableBytes()), buffer, isValue, isLocal));
return srLanAdjIdBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Weight in project bgpcep by opendaylight.
the class SrAttributeParserTest method testSrLanAdjIdOspf.
@Test
public void testSrLanAdjIdOspf() {
final byte[] tested = { (byte) 0x60, 10, 0, 0, 1, 2, 3, 4, 0, 0x5d, (byte) 0xc0 };
final SrLanAdjIds srLanAdjId = new SrLanAdjIdsBuilder().setFlags(OSPF_LAN_ADJ_FLAGS).setWeight(new Weight(Uint8.TEN)).setNeighborId(new Ipv4AddressNoZone("1.2.3.4")).setSidLabelIndex(new LocalLabelCaseBuilder().setLocalLabel(new MplsLabel(Uint32.valueOf(24000L))).build()).build();
assertEquals(srLanAdjId, SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(Unpooled.wrappedBuffer(tested), ProtocolId.Ospf));
final ByteBuf serializedData = SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifier(srLanAdjId);
assertArrayEquals(tested, ByteArray.readAllBytes(serializedData));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev200120.Weight in project bgpcep by opendaylight.
the class SrAttributeParserTest method testRangeTlvIpv6.
@Test
public void testRangeTlvIpv6() {
final byte[] tested = Bytes.concat(new byte[] { 0, 0, 0, 5, // binding sid
4, // binding sid
(byte) 0x88, // binding sid
0, // binding sid
0x34, // binding sid
5, // binding sid
0x48, // binding sid
0, // binding sid
0, // binding sub-tlvs
4, (byte) 0x8c, 0, 0x14, 0, 0, 0, // IPv6 ERO
0 }, // IPv6 ERO
IPV6_A_BYTES, // IPv6 ERO backup
new byte[] { 4, (byte) 0x8f, 0, 0x14, 0, 0, 0, 0 }, // IPv6 ERO backup
IPV6_B_BYTES);
final SrRange parsedRange = RangeTlvParser.parseSrRange(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1);
final List<SubTlvs> rangeSubTlvs = new ArrayList<>();
final List<BindingSubTlvs> bindingSubTlvs = new ArrayList<>();
bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(new Ipv6EroCaseBuilder().setIpv6Ero(new Ipv6EroBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6AddressNoZone(IPV6_A)).build()).build()).build());
bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv(new Ipv6EroBackupCaseBuilder().setIpv6EroBackup(new Ipv6EroBackupBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6AddressNoZone(IPV6_B)).build()).build()).build());
rangeSubTlvs.add(new SubTlvsBuilder().setRangeSubTlv(new BindingSidTlvCaseBuilder().setWeight(new Weight(Uint8.valueOf(5))).setFlags(BINDING_FLAGS).setBindingSubTlvs(bindingSubTlvs).build()).build());
final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(Uint16.valueOf(5)).setSubTlvs(rangeSubTlvs).build();
assertEquals(expected, parsedRange);
final ByteBuf serializedRange = Unpooled.buffer();
RangeTlvParser.serializeSrRange(parsedRange, serializedRange);
assertArrayEquals(tested, ByteArray.getAllBytes(serializedRange));
}
Aggregations