use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order 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);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project bgpcep by opendaylight.
the class AbstractAllPathsRouteEntry method selectBest.
@Override
public final boolean selectBest(final long localAs) {
final List<AddPathBestPath> newBestPathList = new ArrayList<>();
final List<RouteKey> keyList = this.offsets.getRouteKeysList();
if (!keyList.isEmpty()) {
/* we set the best path first on List for not supported Add path cases*/
final AddPathBestPath newBest = selectBest(localAs, keyList);
newBestPathList.add(newBest);
keyList.remove(newBest.getRouteKey());
/*we add the rest of path, regardless in what order they are, since this is all path case */
for (final RouteKey key : keyList) {
final int offset = this.offsets.offsetOf(key);
final Attributes attributes = this.offsets.getValue(this.values, offset);
requireNonNull(key.getRouteId(), "Router ID may not be null");
if (attributes != null) {
final BestPathState state = new BestPathStateImpl(attributes);
final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset, this.offsets.getValue(this.pathsId, offset));
newBestPathList.add(bestPath);
}
}
}
return isBestPathNew(ImmutableList.copyOf(newBestPathList));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project bgpcep by opendaylight.
the class BaseAbstractRouteEntry method fillAdjRibsOut.
@VisibleForTesting
@SuppressWarnings("unchecked")
private void fillAdjRibsOut(@Nullable final Attributes attributes, @Nullable final Route route, final Identifier routeKey, final PeerId fromPeerId, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
/*
* We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
* expose from which client a particular route was learned from in the local RIB, and have
* the listener perform filtering.
*
* We walk the policy set in order to minimize the amount of work we do for multiple peers:
* if we have two eBGP peers, for example, there is no reason why we should perform the translation
* multiple times.
*/
final TablesKey localTK = routeEntryDep.getLocalTablesKey();
final BGPRibRoutingPolicy routingPolicies = routeEntryDep.getRoutingPolicies();
final RIBSupport ribSupport = routeEntryDep.getRibSupport();
for (final Peer toPeer : this.peerTracker.getPeers()) {
if (!filterRoutes(fromPeerId, toPeer, localTK)) {
continue;
}
Optional<Attributes> effAttr = Optional.empty();
final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
if (fromPeer != null && attributes != null) {
final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
effAttr = routingPolicies.applyExportPolicies(routeEntry, attributes);
}
final InstanceIdentifier ribOutTarget = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKey);
if (effAttr.isPresent() && route != null) {
LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget, route);
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget.child(Attributes.class), effAttr.get());
} else {
LOG.trace("Removing {} from transaction for peer {}", ribOutTarget, toPeer.getPeerId());
tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutTarget);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project bgpcep by opendaylight.
the class PCEPTlvParserTest method testOrderTlv.
@Test
public void testOrderTlv() throws PCEPDeserializerException {
final OrderTlvParser parser = new OrderTlvParser();
final Order tlv = new OrderBuilder().setDelete(0xFFFFFFFFL).setSetup(0x00000001L).build();
assertEquals(tlv, parser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(orderBytes, 4))));
final ByteBuf buff = Unpooled.buffer();
parser.serializeTlv(tlv, buff);
assertArrayEquals(orderBytes, ByteArray.getAllBytes(buff));
assertNull(parser.parseTlv(null));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.order.tlv.Order in project bgpcep by opendaylight.
the class OrderTlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof Order, "OrderTlv is mandatory.");
final Order otlv = (Order) tlv;
final ByteBuf body = Unpooled.buffer();
writeUnsignedInt(otlv.getDelete(), body);
writeUnsignedInt(otlv.getSetup(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
Aggregations