2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.neutron.mapper;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.ExecutionException;
15 import javax.annotation.Nullable;
17 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.l3.prefix.fields.EndpointL3Gateways;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.l3.prefix.fields.EndpointL3GatewaysBuilder;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import com.google.common.base.Preconditions;
37 import com.google.common.collect.ImmutableList;
39 public class EndpointRegistrator {
41 private static final Logger LOG = LoggerFactory.getLogger(EndpointRegistrator.class);
42 private final EndpointService epService;
44 public EndpointRegistrator(EndpointService epService) {
45 this.epService = Preconditions.checkNotNull(epService);
48 public boolean registerEndpoint(RegisterEndpointInput regEndpointInput) {
50 RpcResult<Void> rpcResult = epService.registerEndpoint(regEndpointInput).get();
51 if (!rpcResult.isSuccessful()) {
52 LOG.warn("Illegal state - registerEndpoint was not successful. Input of RPC: {}", regEndpointInput);
56 } catch (InterruptedException | ExecutionException e) {
57 LOG.error("registerEndpoint failed. {}", regEndpointInput, e);
62 public boolean unregisterEndpoint(UnregisterEndpointInput unregEndpointInput) {
64 RpcResult<Void> rpcResult = epService.unregisterEndpoint(unregEndpointInput).get();
65 if (!rpcResult.isSuccessful()) {
66 LOG.warn("Illegal state - unregisterEndpoint was not successful. Input of RPC: {}", unregEndpointInput);
70 } catch (InterruptedException | ExecutionException e) {
71 LOG.error("unregisterEndpoint failed. {}", unregEndpointInput, e);
76 public boolean registerExternalL3PrefixEndpoint(IpPrefix ipPrefix, L3ContextId l3Context,
77 @Nullable IpAddress gatewayIp, TenantId tenantId) {
78 List<EndpointL3Gateways> l3Gateways = new ArrayList<EndpointL3Gateways>();
79 if (gatewayIp != null) {
80 EndpointL3Gateways l3Gateway =
81 new EndpointL3GatewaysBuilder().setIpAddress(gatewayIp).setL3Context(l3Context).build();
82 l3Gateways.add(l3Gateway);
84 RegisterL3PrefixEndpointInput registerL3PrefixEpRpcInput = new RegisterL3PrefixEndpointInputBuilder()
85 .setL3Context(l3Context)
86 .setIpPrefix(ipPrefix)
87 .setEndpointGroup(MappingUtils.EPG_EXTERNAL_ID)
89 .setEndpointL3Gateways(l3Gateways)
90 .setTimestamp(System.currentTimeMillis())
93 RpcResult<Void> rpcResult = epService.registerL3PrefixEndpoint(registerL3PrefixEpRpcInput).get();
94 if (!rpcResult.isSuccessful()) {
95 LOG.warn("Illegal state - registerExternalL3PrefixEndpoint was not successful. Input of RPC: {}",
96 registerL3PrefixEpRpcInput);
100 } catch (InterruptedException | ExecutionException e) {
101 LOG.error("registerExternalL3PrefixEndpoint failed. {}", registerL3PrefixEpRpcInput, e);
106 public boolean registerL3EndpointAsExternalGateway(TenantId tenantId, IpAddress ipAddress, L3ContextId l3Context,
107 NetworkDomainId networkContainment) {
108 RegisterEndpointInput registerEndpointInput =
109 new RegisterEndpointInputBuilder()
110 .setL3Address(ImmutableList
111 .of(new L3AddressBuilder().setL3Context(l3Context).setIpAddress(ipAddress).build()))
113 .setNetworkContainment(networkContainment)
114 .setEndpointGroups(ImmutableList.of(MappingUtils.EPG_EXTERNAL_ID))
115 .setTimestamp(System.currentTimeMillis())
118 RpcResult<Void> rpcResult = epService.registerEndpoint(registerEndpointInput).get();
119 if (!rpcResult.isSuccessful()) {
120 LOG.warn("Illegal state - registerL3EndpointAsExternalGateway was not successful. Input of RPC: {}",
121 registerEndpointInput);
124 } catch (InterruptedException | ExecutionException e) {
125 LOG.error("registerL3EndpointAsExternalGateway failed. {}", registerEndpointInput, e);