2 * Copyright (c) 2014 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.renderer.opflex;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.ScheduledExecutorService;
15 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.Endpoints;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.OpflexOverlayContext;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.OpflexOverlayContextBuilder;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import com.google.common.base.Optional;
31 import com.google.common.util.concurrent.FutureCallback;
32 import com.google.common.util.concurrent.Futures;
33 import com.google.common.util.concurrent.ListenableFuture;
37 * A context for mapping OpFlex messaging to asynchronous
38 * requests to the Endpoint Registry's list of L2 Endpoints.
43 public class L2EprOperation implements EprOperation, FutureCallback<Optional<Endpoint>>{
45 private EprOpCallback cb;
47 private InstanceIdentifier<Endpoint> iid;
49 private String agentId;
51 private EndpointGroupId egid;
52 private L2BridgeDomainId l2bdid;
53 private MacAddress mac;
54 private List<L3Address> l3al;
58 public L2EprOperation(int prr) {
59 this.timeout = Long.valueOf(prr);
60 this.l3al = new ArrayList<L3Address>();
63 public L2EprOperation() {
66 public void setAgentId(String agentId) {
67 this.agentId = agentId;
70 public void setTenantId(TenantId tid) {
74 public void setEndpointGroupId(EndpointGroupId egid) {
78 public void setContextId(L2BridgeDomainId l2bdid) {
82 public void setMacAddress(MacAddress mac) {
86 public void setL3AddressList(List<L3Address> l3al) {
90 public void addL3Address(L3Address l3a) {
94 public Endpoint getEp() {
98 public void setEp(Endpoint ep) {
102 public Endpoint buildEp() {
103 EndpointBuilder epBuilder = new EndpointBuilder();
104 OpflexOverlayContextBuilder oocb = new OpflexOverlayContextBuilder();
105 oocb.setAgentId(this.agentId);
107 epBuilder.setTenant(this.tid)
108 .setEndpointGroup(this.egid)
109 .setL2Context(this.l2bdid)
111 .setMacAddress(this.mac)
112 .setTimestamp(this.timeout)
113 .addAugmentation(OpflexOverlayContext.class, oocb.build());
115 // TODO: add support for conditions
116 //epBuilder.setCondition(new List<ConditionName>());
118 return epBuilder.build();
122 * Create or update an L2 Endpoint in the Endpoint Registry
124 * @param wt The Write Transaction
127 public void put(WriteTransaction wt) {
130 this.iid = InstanceIdentifier.builder(Endpoints.class)
131 .child(Endpoint.class, ep.getKey())
133 wt.put(LogicalDatastoreType.OPERATIONAL, iid, ep);
137 public void delete(WriteTransaction wt) {
140 this.iid = InstanceIdentifier.builder(Endpoints.class)
141 .child(Endpoint.class, ep.getKey())
143 wt.delete(LogicalDatastoreType.OPERATIONAL, iid);
147 * Get/read an L2 endpoint in the registry, given a context
150 * @param rot The read transaction
153 public void read(ReadOnlyTransaction rot,
154 ScheduledExecutorService executor) {
157 this.iid = InstanceIdentifier.builder(Endpoints.class)
158 .child(Endpoint.class, ep.getKey())
161 ListenableFuture<Optional<Endpoint>> dao =
162 rot.read(LogicalDatastoreType.OPERATIONAL, iid);
163 Futures.addCallback(dao, this, executor);
167 public void setCallback(EprOpCallback callback) {
173 public void onSuccess(final Optional<Endpoint> result) {
174 if (!result.isPresent()) {
176 * This EP doesn't exist in the registry. If
177 * all of the data store queries have been made,
178 * and we still don't have any EPs, then provide
191 public void onFailure(Throwable t) {