+
+ public void updateServiceGatewayList(TypedWriteTransaction<Datastore.Configuration> tx, String serviceGatewayPod,
+ String serviceGatewayIp, String serviceGatewayMac) {
+ InstanceIdentifier<ServiceGateway> serviceGatewayInstanceIdentifier =
+ InstanceIdentifier.builder(ServiceGatewayInfo.class).child(
+ ServiceGateway.class, new ServiceGatewayKey(serviceGatewayPod)).build();
+ ServiceGateway serviceGateway = new ServiceGatewayBuilder().setGatewayPodName(serviceGatewayPod)
+ .setGatewayPodIpAddress(serviceGatewayIp).setGatewayPodMacAddress(serviceGatewayMac).build();
+ tx.put(serviceGatewayInstanceIdentifier, serviceGateway);
+ }
+
+ private InstanceIdentifier<ServiceGatewayInfo> buildServiceGatewayInstanceIndentifier() {
+ return InstanceIdentifier.builder(ServiceGatewayInfo.class).build();
+ }
+
+ public void updateVpnInterfaceWithExtraRouteAdjacency(TypedReadWriteTransaction<Datastore.Configuration> tx,
+ Services services) throws ExecutionException,
+ InterruptedException {
+ if (services.getClusterIpAddress() == null) {
+ LOG.error("Incorrect input received for extra route. {}", services.getName());
+ } else {
+ LOG.info("update vpn-interface with extra route adjacencies for {}", services.getName());
+ Optional<ServiceGatewayInfo> serviceGatewayList = tx.read(buildServiceGatewayInstanceIndentifier()).get();
+ if (serviceGatewayList.isPresent() && serviceGatewayList.get() != null) {
+ for (ServiceGateway serviceGateway : serviceGatewayList.get().nonnullServiceGateway()) {
+ String nextHop = serviceGateway.getGatewayPodIpAddress();
+ IpAddress destination = services.getClusterIpAddress();
+ String destinationIpValue = destination.getIpv4Address() != null
+ ? destination.getIpv4Address().getValue() :
+ destination.getIpv6Address().getValue();
+ String destinationIpPrefix = destination.getIpv4Address() != null ? destinationIpValue + "/32"
+ : destinationIpValue + "/128";
+ String infName = serviceGateway.getGatewayPodName();
+ if (infName != null) {
+ LOG.info("Updating extra route for destination {} onto vpn {} with nexthop {} and infName {}",
+ destination, services.getClusterId(), nextHop, infName);
+ InstanceIdentifier<Adjacency> path = InstanceIdentifier.builder(VpnInterfaces.class)
+ .child(VpnInterface.class, new VpnInterfaceKey(infName)).build()
+ .augmentation(Adjacencies.class).child(Adjacency.class,
+ new AdjacencyKey(destinationIpPrefix));
+ Adjacency erAdj = new AdjacencyBuilder().setIpAddress(destinationIpPrefix)
+ .setNextHopIpList(Collections.singletonList(nextHop))
+ .setAdjacencyType(Adjacency.AdjacencyType.ExtraRoute).build();
+ tx.put(path, erAdj);
+
+ } else {
+ LOG.error("Unable to find VPN NextHop interface to apply extra-route destination {} on VPN {} "
+ + "with nexthop {}", destination, services.getClusterId(), nextHop);
+ }
+ }
+ }
+ }
+ }