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 com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableList;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.ExecutionException;
18 import javax.annotation.Nullable;
20 import org.opendaylight.groupbasedpolicy.neutron.mapper.util.MappingUtils;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.RegisterEndpointInputBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.UnregisterEndpointInputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointReg;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.AddressEndpointUnreg;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.unregister.endpoint.input.AddressEndpointUnregBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L3ContextId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.EndpointService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterL3PrefixEndpointInputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3AddressBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.l3.prefix.fields.EndpointL3Gateways;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.l3.prefix.fields.EndpointL3GatewaysBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.unregister.endpoint.input.L3Builder;
41 import org.opendaylight.yangtools.yang.common.RpcResult;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 public class EndpointRegistrator {
47 private static final Logger LOG = LoggerFactory.getLogger(EndpointRegistrator.class);
48 private final EndpointService epService;
49 private final BaseEndpointService baseEpService;
51 public EndpointRegistrator(EndpointService epService, BaseEndpointService baseEpService) {
52 this.epService = Preconditions.checkNotNull(epService);
53 this.baseEpService = Preconditions.checkNotNull(baseEpService);
56 public boolean registerEndpoint(AddressEndpointReg regEndpointInput) {
57 RegisterEndpointInput regBaseEpInput = new RegisterEndpointInputBuilder().setAddressEndpointReg(
58 ImmutableList.<AddressEndpointReg>of(regEndpointInput))
60 return registerEndpoint(regBaseEpInput);
63 public boolean registerEndpoint(RegisterEndpointInput regBaseEpInput) {
65 RpcResult<Void> rpcResult = baseEpService.registerEndpoint(regBaseEpInput).get();
66 if (!rpcResult.isSuccessful()) {
67 LOG.warn("Illegal state - register Base Endpoint was not successful. Input of RPC: {}", regBaseEpInput);
71 } catch (InterruptedException | ExecutionException e) {
72 LOG.error("Base endpoint registration failed. {}", regBaseEpInput, e);
78 @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names,
79 // this will be removed when deprecated classes will be cleared.
80 public boolean registerEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput regEndpointInput) {
82 RpcResult<Void> rpcResult = epService.registerEndpoint(regEndpointInput).get();
83 if (!rpcResult.isSuccessful()) {
84 LOG.warn("Illegal state - register Endpoint was not successful. Input of RPC: {}", regEndpointInput);
88 } catch (InterruptedException | ExecutionException e) {
89 LOG.error("registerEndpoint failed. {}", regEndpointInput, e);
94 public boolean unregisterEndpoint(AddressEndpointUnreg addrEpUnreg) {
95 UnregisterEndpointInput input = new UnregisterEndpointInputBuilder().setAddressEndpointUnreg(
96 ImmutableList.<AddressEndpointUnreg>of(new AddressEndpointUnregBuilder().setKey(addrEpUnreg.getKey())
98 return unregisterEndpoint(input);
101 public boolean unregisterEndpoint(UnregisterEndpointInput input) {
103 RpcResult<Void> rpcResult = baseEpService.unregisterEndpoint(input).get();
104 if (!rpcResult.isSuccessful()) {
105 LOG.warn("Illegal state - unregisterEndpoint was not successful. Input of RPC: {}", input);
109 } catch (InterruptedException | ExecutionException e) {
110 LOG.error("unregisterEndpoint failed. {}", input, e);
116 @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names,
117 // this will be removed when deprecated classes will be cleared.
118 public boolean unregisterEndpoint(org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput unregEndpointInput) {
120 RpcResult<Void> rpcResult = epService.unregisterEndpoint(unregEndpointInput).get();
121 if (!rpcResult.isSuccessful()) {
122 LOG.warn("Illegal state - unregisterEndpoint was not successful. Input of RPC: {}", unregEndpointInput);
126 } catch (InterruptedException | ExecutionException e) {
127 LOG.error("unregisterEndpoint failed. {}", unregEndpointInput, e);
133 public boolean registerExternalL3PrefixEndpoint(IpPrefix ipPrefix, L3ContextId l3Context,
134 @Nullable IpAddress gatewayIp, TenantId tenantId) {
135 List<EndpointL3Gateways> l3Gateways = new ArrayList<EndpointL3Gateways>();
136 if (gatewayIp != null) {
137 EndpointL3Gateways l3Gateway =
138 new EndpointL3GatewaysBuilder().setIpAddress(gatewayIp).setL3Context(l3Context).build();
139 l3Gateways.add(l3Gateway);
141 RegisterL3PrefixEndpointInput registerL3PrefixEpRpcInput = new RegisterL3PrefixEndpointInputBuilder()
142 .setL3Context(l3Context)
143 .setIpPrefix(ipPrefix)
144 .setEndpointGroup(MappingUtils.EPG_EXTERNAL_ID)
146 .setEndpointL3Gateways(l3Gateways)
147 .setTimestamp(System.currentTimeMillis())
150 RpcResult<Void> rpcResult = epService.registerL3PrefixEndpoint(registerL3PrefixEpRpcInput).get();
151 if (!rpcResult.isSuccessful()) {
152 LOG.warn("Illegal state - registerExternalL3PrefixEndpoint was not successful. Input of RPC: {}",
153 registerL3PrefixEpRpcInput);
157 } catch (InterruptedException | ExecutionException e) {
158 LOG.error("registerExternalL3PrefixEndpoint failed. {}", registerL3PrefixEpRpcInput, e);
164 @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names,
165 // this will be removed when deprecated classes will be cleared.
166 public boolean registerL3EpAsExternalGateway(TenantId tenantId, IpAddress ipAddress, L3ContextId l3Context,
167 NetworkDomainId networkContainment) {
168 org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput
169 registerEndpointInput =
170 new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInputBuilder()
172 ImmutableList.of(new L3AddressBuilder().setL3Context(l3Context).setIpAddress(ipAddress).build()))
174 .setNetworkContainment(networkContainment)
175 .setEndpointGroups(ImmutableList.of(MappingUtils.EPG_EXTERNAL_ID))
176 .setTimestamp(System.currentTimeMillis())
179 RpcResult<Void> rpcResult = epService.registerEndpoint(registerEndpointInput).get();
180 if (!rpcResult.isSuccessful()) {
181 LOG.warn("Illegal state - registerL3EndpointAsExternalGateway was not successful. Input of RPC: {}",
182 registerEndpointInput);
185 } catch (InterruptedException | ExecutionException e) {
186 LOG.error("registerL3EndpointAsExternalGateway failed. {}", registerEndpointInput, e);
193 @SuppressWarnings("checkstyle:LineLength") // Longer lines in this method are caused by long package names,
194 // this will be removed when deprecated classes will be cleared.
195 public boolean unregisterL3EpAsExternalGateway(IpAddress ipAddress, L3ContextId l3Context) {
196 org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInput
197 unregisterEndpointInput =
198 new org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.UnregisterEndpointInputBuilder()
199 .setL3(ImmutableList.of(new L3Builder().setL3Context(l3Context).setIpAddress(ipAddress).build()))
203 RpcResult<Void> rpcResult = epService.unregisterEndpoint(unregisterEndpointInput).get();
204 if (!rpcResult.isSuccessful()) {
205 LOG.warn("Illegal state - unregisterL3EndpointAsExternalGateway was not successful. Input of RPC: {}",
206 unregisterEndpointInput);
209 } catch (InterruptedException | ExecutionException e) {
210 LOG.error("unregisterL3EndpointAsExternalGateway failed. {}", unregisterEndpointInput, e);