+ /**
+ * Creates the corresponding static routes in the specified VPN. These static routes must be point to an
+ * InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink. Otherwise the
+ * route will be ignored.
+ *
+ * @param vpnName the VPN identifier
+ * @param interVpnLinkRoutes The list of static routes
+ * @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink
+ */
+ public void addInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes,
+ HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
+ for ( Routes route : interVpnLinkRoutes ) {
+ String nexthop = String.valueOf(route.getNexthop().getValue());
+ String destination = String.valueOf(route.getDestination().getValue());
+ InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
+ if ( isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink) ) {
+ AddStaticRouteInput rpcInput =
+ new AddStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop)
+ .setVpnInstanceName(vpnName.getValue())
+ .build();
+ Future<RpcResult<AddStaticRouteOutput>> labelOuputFtr = vpnRpcService.addStaticRoute(rpcInput);
+ RpcResult<AddStaticRouteOutput> rpcResult;
+ try {
+ rpcResult = labelOuputFtr.get();
+ if ( rpcResult.isSuccessful() ) {
+ LOG.debug("Label generated for destination {} is: {}",
+ destination, rpcResult.getResult().getLabel());
+ } else {
+ LOG.warn("RPC call to add a static Route to {} with nexthop {} returned with errors {}",
+ destination, nexthop, rpcResult.getErrors());
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.warn("Error happened while invoking addStaticRoute RPC: ", e);
+ }
+ } else {
+ // Any other case is a fault.
+ LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
+ String.valueOf(route.getDestination().getValue()), nexthop );
+ continue;
+ }
+ }
+ }
+
+ /**
+ * Removes the corresponding static routes from the specified VPN. These static routes point to an
+ * InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink.
+ *
+ * @param vpnName the VPN identifier
+ * @param interVpnLinkRoutes The list of static routes
+ * @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink
+ */
+ public void removeInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes,
+ HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
+ for ( Routes route : interVpnLinkRoutes ) {
+ String nexthop = String.valueOf(route.getNexthop().getValue());
+ String destination = String.valueOf(route.getDestination().getValue());
+ InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
+ if ( isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink) ) {
+ RemoveStaticRouteInput rpcInput =
+ new RemoveStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop)
+ .setVpnInstanceName(vpnName.getValue())
+ .build();
+ vpnRpcService.removeStaticRoute(rpcInput);
+ } else {
+ // Any other case is a fault.
+ LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink",
+ String.valueOf(route.getDestination().getValue()), nexthop );
+ continue;
+ }
+ }
+ }
+
+ /*
+ * Returns true if the specified nexthop is the other endpoint in an
+ * InterVpnLink, regarding one of the VPN's point of view.
+ */
+ private boolean isNexthopTheOtherVpnLinkEndpoint(String nexthop, String thisVpnUuid, InterVpnLink interVpnLink) {
+ return
+ interVpnLink != null
+ && ( (interVpnLink.getFirstEndpoint().getVpnUuid().getValue().equals(thisVpnUuid)
+ && interVpnLink.getSecondEndpoint().getIpAddress().getValue().equals(nexthop))
+ || (interVpnLink.getSecondEndpoint().getVpnUuid().getValue().equals(thisVpnUuid )
+ && interVpnLink.getFirstEndpoint().getIpAddress().getValue().equals(nexthop)) );
+ }
+
+ protected List<Adjacency> getAdjacencyforExtraRoute(Uuid vpnId, List<Routes> routeList, String fixedIp) {