Mostly reduced method complexity.
Change-Id: Ib3bb6a6cc95b854afb61534dc35a45652fc2d2c8
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder =
Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(Stats.QNAME));
builder.withChild(ImmutableNodes.leafNode(PEER_STATS_TIMESTAMP_QNAME, timestamp.getValue()));
- if (stat.getTlvs() != null) {
- final Tlvs tlvs = stat.getTlvs();
- if (tlvs.getRejectedPrefixesTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT0_QNAME, tlvs.getRejectedPrefixesTlv().getCount().getValue()));
- }
- if (tlvs.getDuplicatePrefixAdvertisementsTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT1_QNAME, tlvs.getDuplicatePrefixAdvertisementsTlv().getCount().getValue()));
- }
- if (tlvs.getDuplicateWithdrawsTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT2_QNAME, tlvs.getDuplicateWithdrawsTlv().getCount().getValue()));
- }
- if (tlvs.getInvalidatedClusterListLoopTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT3_QNAME, tlvs.getInvalidatedClusterListLoopTlv().getCount().getValue()));
- }
- if (tlvs.getInvalidatedAsPathLoopTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT4_QNAME, tlvs.getInvalidatedAsPathLoopTlv().getCount().getValue()));
- }
- if (tlvs.getInvalidatedOriginatorIdTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT5_QNAME, tlvs.getInvalidatedOriginatorIdTlv().getCount().getValue()));
- }
- if (tlvs.getInvalidatedAsConfedLoopTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT6_QNAME, tlvs.getInvalidatedAsConfedLoopTlv().getCount().getValue()));
- }
- if (tlvs.getAdjRibsInRoutesTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT7_QNAME, tlvs.getAdjRibsInRoutesTlv().getCount().getValue()));
- }
- if (tlvs.getLocRibRoutesTlv() != null) {
- builder.withChild(ImmutableNodes.leafNode(STAT8_QNAME, tlvs.getLocRibRoutesTlv().getCount().getValue()));
- }
+ final Tlvs tlvs = stat.getTlvs();
+ if (tlvs != null) {
+ statsForTlvs(tlvs, builder);
}
return builder.build();
}
+ private static void statsForTlvs(final Tlvs tlvs, final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> builder) {
+ if (tlvs.getRejectedPrefixesTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT0_QNAME, tlvs.getRejectedPrefixesTlv().getCount().getValue()));
+ }
+ if (tlvs.getDuplicatePrefixAdvertisementsTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT1_QNAME, tlvs.getDuplicatePrefixAdvertisementsTlv().getCount().getValue()));
+ }
+ if (tlvs.getDuplicateWithdrawsTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT2_QNAME, tlvs.getDuplicateWithdrawsTlv().getCount().getValue()));
+ }
+ if (tlvs.getInvalidatedClusterListLoopTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT3_QNAME, tlvs.getInvalidatedClusterListLoopTlv().getCount().getValue()));
+ }
+ if (tlvs.getInvalidatedAsPathLoopTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT4_QNAME, tlvs.getInvalidatedAsPathLoopTlv().getCount().getValue()));
+ }
+ if (tlvs.getInvalidatedOriginatorIdTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT5_QNAME, tlvs.getInvalidatedOriginatorIdTlv().getCount().getValue()));
+ }
+ if (tlvs.getInvalidatedAsConfedLoopTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT6_QNAME, tlvs.getInvalidatedAsConfedLoopTlv().getCount().getValue()));
+ }
+ if (tlvs.getAdjRibsInRoutesTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT7_QNAME, tlvs.getAdjRibsInRoutesTlv().getCount().getValue()));
+ }
+ if (tlvs.getLocRibRoutesTlv() != null) {
+ builder.withChild(ImmutableNodes.leafNode(STAT8_QNAME, tlvs.getLocRibRoutesTlv().getCount().getValue()));
+ }
+ }
+
private static String getStringIpAddress(final IpAddress ipAddress) {
if (ipAddress.getIpv4Address() != null) {
return ipAddress.getIpv4Address().getValue();
if (this == obj) {
return true;
}
- if (obj == null) {
- return false;
- }
- if (this.getClass() != obj.getClass()) {
+ if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
final BGPErrorIdentifier other = (BGPErrorIdentifier) obj;
- if (this.code != other.code) {
- return false;
- }
- if (this.subcode != other.subcode) {
+ if (this.code != other.code || this.subcode != other.subcode) {
return false;
}
return true;
}
}
final List<Ipv4Prefix> nlri = Ipv4Util.prefixListForBytes(ByteArray.readAllBytes(buffer));
- if (nlri != null && !nlri.isEmpty()) {
+ if (!nlri.isEmpty()) {
builder.setNlri(new NlriBuilder().setNlri(nlri).build());
}
final Update msg = builder.build();
}
final WithdrawnRoutes routes = mpUnreachNlri.getWithdrawnRoutes();
if (routes != null) {
- if (routes.getDestinationType() instanceof DestinationIpv4Case) {
- final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case)routes.getDestinationType();
- if (destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes() != null) {
- for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
- byteAggregator.writeBytes(Ipv4Util.bytesForPrefixBegin(ipv4Prefix.getPrefix()));
- }
+ serializeRoutes(routes, byteAggregator);
+ }
+ }
+
+ private static void serializeRoutes(final WithdrawnRoutes routes, final ByteBuf byteAggregator) {
+ if (routes.getDestinationType() instanceof DestinationIpv4Case) {
+ final DestinationIpv4Case destinationIpv4Case = (DestinationIpv4Case) routes.getDestinationType();
+ if (destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes() != null) {
+ for (final Ipv4Prefixes ipv4Prefix : destinationIpv4Case.getDestinationIpv4().getIpv4Prefixes()) {
+ byteAggregator.writeBytes(Ipv4Util.bytesForPrefixBegin(ipv4Prefix.getPrefix()));
}
- } else if (routes.getDestinationType() instanceof DestinationIpv6Case) {
- final DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) routes.getDestinationType();
- if (destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes() != null) {
- for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
- byteAggregator.writeBytes(Ipv6Util.bytesForPrefixBegin(ipv6Prefix.getPrefix()));
- }
+ }
+ } else if (routes.getDestinationType() instanceof DestinationIpv6Case) {
+ final DestinationIpv6Case destinationIpv6Case = (DestinationIpv6Case) routes.getDestinationType();
+ if (destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes() != null) {
+ for (final Ipv6Prefixes ipv6Prefix : destinationIpv6Case.getDestinationIpv6().getIpv6Prefixes()) {
+ byteAggregator.writeBytes(Ipv6Util.bytesForPrefixBegin(ipv6Prefix.getPrefix()));
}
}
}
final Bootstrap b = new Bootstrap();
final BGPProtocolSessionPromise p = new BGPProtocolSessionPromise(this.executor, address, strategy, b);
- b.option(ChannelOption.SO_KEEPALIVE, Boolean.valueOf(true));
+ b.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
b.handler(BGPChannel.createChannelInitializer(initializer, p));
this.customizeBootstrap(b);
- this.setWorkerGroup(b);
+ setWorkerGroup(b);
p.connect();
LOG.debug("Client created.");
return p;
final Bootstrap b = new Bootstrap();
final BGPReconnectPromise p = new BGPReconnectPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE, address,
connectStrategyFactory, b, BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.hf.getDecoders(), snf, BGPDispatcherImpl.this.hf.getEncoders()));
- b.option(ChannelOption.SO_KEEPALIVE, Boolean.valueOf(true));
+ b.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
this.customizeBootstrap(b);
- this.setWorkerGroup(b);
+ setWorkerGroup(b);
p.connect();
this.keys = null;
try {
b.channel(NioServerSocketChannel.class);
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
LOG.trace("Not overriding channelFactory on bootstrap {}", b, e);
}
}
}
try {
b.channel(NioSocketChannel.class);
- } catch (IllegalStateException e) {
+ } catch (final IllegalStateException e) {
LOG.trace("Not overriding channelFactory on bootstrap {}", b, e);
}
}
public static <S extends BGPSession> ChannelHandler createChannelInitializer(final ChannelPipelineInitializer initializer, final Promise<S> promise) {
return new ChannelInitializer<SocketChannel>() {
@Override
- protected void initChannel(SocketChannel ch) {
+ protected void initChannel(final SocketChannel ch) {
initializer.initializeChannel(ch, promise);
}
};
isEOR = true;
}
}
+ syncType(type, isEOR);
+ }
+
+ private void syncType(final TablesKey type, final boolean isEOR) {
final SyncVariables s = this.syncStorage.get(type);
if (s == null) {
LOG.warn("BGPTableType was not present in open message : {}", type);
* are better.
*/
final BestPathState state = new BestPathState(attrs);
- if (this.bestOriginatorId == null || !isExistingPathBetter(originatorId, state)) {
+ if (this.bestOriginatorId == null || !isExistingPathBetter(state)) {
LOG.trace("Selecting path from router {}", routerId);
this.bestOriginatorId = originatorId;
this.bestRouterId = routerId;
/**
* Chooses best route according to BGP best path selection.
*
- * @param originatorId of the new route
* @param state attributes of the new route
* @return true if the existing path is better, false if the new path is better
*/
- private boolean isExistingPathBetter(@Nonnull final UnsignedInteger originatorId, @Nonnull final BestPathState state) {
+ private boolean isExistingPathBetter(@Nonnull final BestPathState state) {
// 1. prefer path with accessible nexthop
// - we assume that all nexthops are accessible
-
/*
* 2. prefer path with higher LOCAL_PREF
*
if (state.getLocalPref() != null && state.getLocalPref() < this.bestState.getLocalPref()) {
return true;
}
-
// 3. prefer learned path
// - we assume that all paths are learned
// This trick relies on the order in which the values are declared in the model.
return no.ordinal() > bo.ordinal();
}
-
// FIXME: we should be able to cache the best AS
final Long bestAs = this.bestState.getPeerAs();
final Long newAs = state.getPeerAs();
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeFactory;
import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
final DOMDataBrokerExtension domDatatreeChangeService = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
this.service = domDatatreeChangeService;
- this.efWriter = EffectiveRibInWriter.create(getService(), this.createPeerChain(this), getYangRibId(), pd, this.ribContextRegistry);
+ this.efWriter = EffectiveRibInWriter.create(getService(), createPeerChain(this), getYangRibId(), pd, this.ribContextRegistry);
LOG.debug("Effective RIB created.");
for (final BgpTableType t : this.localTables) {
} catch (final TransactionCommitFailedException e1) {
LOG.error("Failed to initiate LocRIB for key {}", key, e1);
}
- this.locRibs.add(LocRibWriter.create(this.ribContextRegistry, key, this.createPeerChain(this), getYangRibId(), this.localAs, getService(), pd));
+ this.locRibs.add(LocRibWriter.create(this.ribContextRegistry, key, createPeerChain(this), getYangRibId(), this.localAs, getService(), pd));
}
@Override
getInstanceIdentifier().child(LocRib.class).child(Tables.class, key)).checkedGet();
if (tableMaybe.isPresent()) {
final Tables table = tableMaybe.get();
- if (table.getRoutes() instanceof Ipv4RoutesCase) {
- final Ipv4RoutesCase routesCase = (Ipv4RoutesCase) table.getRoutes();
- if (routesCase.getIpv4Routes() != null && routesCase.getIpv4Routes().getIpv4Route() != null) {
- return routesCase.getIpv4Routes().getIpv4Route().size();
- }
- } else if (table.getRoutes() instanceof Ipv6RoutesCase) {
- final Ipv6RoutesCase routesCase = (Ipv6RoutesCase) table.getRoutes();
- if (routesCase.getIpv6Routes() != null && routesCase.getIpv6Routes().getIpv6Route() != null) {
- return routesCase.getIpv6Routes().getIpv6Route().size();
- }
- }
+ return countIpRoutes(table.getRoutes());
}
} catch (final ReadFailedException e) {
LOG.debug("Failed to read tables", e);
return 0;
}
+ private int countIpRoutes(final Routes routes) {
+ if (routes instanceof Ipv4RoutesCase) {
+ final Ipv4RoutesCase routesCase = (Ipv4RoutesCase) routes;
+ if (routesCase.getIpv4Routes() != null && routesCase.getIpv4Routes().getIpv4Route() != null) {
+ return routesCase.getIpv4Routes().getIpv4Route().size();
+ }
+ } else if (routes instanceof Ipv6RoutesCase) {
+ final Ipv6RoutesCase routesCase = (Ipv6RoutesCase) routes;
+ if (routesCase.getIpv6Routes() != null && routesCase.getIpv6Routes().getIpv6Route() != null) {
+ return routesCase.getIpv6Routes().getIpv6Route().size();
+ }
+ }
+ return 0;
+ }
+
public Set<TablesKey> getLocalTablesKeys() {
return this.localTablesKeys;
}
});
}
- @Deprecated
- protected AbstractTopologyBuilder(final DataBroker dataProvider, final RibReference locRibReference,
- final TopologyId topologyId, final TopologyTypes types, final Class<T> idClass) {
- this(dataProvider, locRibReference, topologyId, types);
- }
-
@Deprecated
public final InstanceIdentifier<Tables> tableInstanceIdentifier(final Class<? extends AddressFamily> afi,
final Class<? extends SubsequentAddressFamily> safi) {
LOG.trace("Transaction chain was already closed, skipping update.");
return;
}
-
final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
LOG.debug("Received data change {} event with transaction {}", changes, trans.getIdentifier());
-
for (final DataTreeModification<T> change : changes) {
try {
- final DataObjectModification<T> root = change.getRootNode();
- switch (root.getModificationType()) {
- case DELETE:
- removeObject(trans, change.getRootPath().getRootIdentifier(), root.getDataBefore());
- break;
- case SUBTREE_MODIFIED:
- case WRITE:
- if (root.getDataBefore() != null) {
- removeObject(trans, change.getRootPath().getRootIdentifier(), root.getDataBefore());
- }
- createObject(trans, change.getRootPath().getRootIdentifier(), root.getDataAfter());
- break;
- default:
- throw new IllegalArgumentException("Unhandled modification type " + root.getModificationType());
- }
+ routeChanged(change, trans);
} catch (final RuntimeException e) {
LOG.warn("Data change {} was not completely propagated to listener {}, aborting", change, this, e);
trans.cancel();
return;
}
}
-
Futures.addCallback(trans.submit(), new FutureCallback<Void>() {
@Override
public void onSuccess(final Void result) {
});
}
+ private void routeChanged(final DataTreeModification<T> change, final ReadWriteTransaction trans) {
+ final DataObjectModification<T> root = change.getRootNode();
+ switch (root.getModificationType()) {
+ case DELETE:
+ removeObject(trans, change.getRootPath().getRootIdentifier(), root.getDataBefore());
+ break;
+ case SUBTREE_MODIFIED:
+ case WRITE:
+ if (root.getDataBefore() != null) {
+ removeObject(trans, change.getRootPath().getRootIdentifier(), root.getDataBefore());
+ }
+ createObject(trans, change.getRootPath().getRootIdentifier(), root.getDataAfter());
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled modification type " + root.getModificationType());
+ }
+ }
+
@Override
public final void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction, final Throwable cause) {
// TODO: restart?
if (routerIdentifier == null) {
return null;
}
-
if (routerIdentifier instanceof IsisNodeCase) {
return isoId(((IsisNodeCase) routerIdentifier).getIsisNode().getIsoSystemId());
- } else if (routerIdentifier instanceof IsisPseudonodeCase) {
+ }
+ if (routerIdentifier instanceof IsisPseudonodeCase) {
final IsisPseudonode r = ((IsisPseudonodeCase) routerIdentifier).getIsisPseudonode();
- return isoId(r.getIsIsRouterIdentifier().getIsoSystemId().getValue()) + '.'
- + Hex.encodeHexString(new byte[] { UnsignedBytes.checkedCast(r.getPsn()) });
- } else if (routerIdentifier instanceof OspfNodeCase) {
+ return isoId(r.getIsIsRouterIdentifier().getIsoSystemId().getValue()) + '.' + Hex.encodeHexString(new byte[] { UnsignedBytes.checkedCast(r.getPsn()) });
+ }
+ if (routerIdentifier instanceof OspfNodeCase) {
return ((OspfNodeCase) routerIdentifier).getOspfNode().getOspfRouterId().toString();
- } else if (routerIdentifier instanceof OspfPseudonodeCase) {
+ }
+ if (routerIdentifier instanceof OspfPseudonodeCase) {
final OspfPseudonode r = ((OspfPseudonodeCase) routerIdentifier).getOspfPseudonode();
return r.getOspfRouterId().toString() + ':' + r.getLanInterface().getValue();
- } else {
- LOG.warn("Unhandled router identifier type {}, fallback to toString()", routerIdentifier.getImplementedInterface());
- return routerIdentifier.toString();
}
+ LOG.warn("Unhandled router identifier type {}, fallback to toString()", routerIdentifier.getImplementedInterface());
+ return routerIdentifier.toString();
}
UriBuilder add(final String prefix, final NodeIdentifier node) {