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;
36 * A context for mapping OpFlex messaging to asynchronous
37 * requests to the Endpoint Registry's list of L2 Endpoints.
41 public class L2EprOperation implements EprOperation, FutureCallback<Optional<Endpoint>> {
43 private EprOpCallback cb;
45 private InstanceIdentifier<Endpoint> iid;
47 private String agentId;
49 private EndpointGroupId egid;
50 private L2BridgeDomainId l2bdid;
51 private MacAddress mac;
52 private List<L3Address> l3al;
55 public L2EprOperation(int prr) {
56 this.timeout = Long.valueOf(prr);
57 this.l3al = new ArrayList<L3Address>();
60 public L2EprOperation() {}
62 public void setAgentId(String agentId) {
63 this.agentId = agentId;
66 public void setTenantId(TenantId tid) {
70 public void setEndpointGroupId(EndpointGroupId egid) {
74 public void setContextId(L2BridgeDomainId l2bdid) {
78 public void setMacAddress(MacAddress mac) {
82 public void setL3AddressList(List<L3Address> l3al) {
86 public void addL3Address(L3Address l3a) {
90 public Endpoint getEp() {
94 public void setEp(Endpoint ep) {
98 public Endpoint buildEp() {
99 EndpointBuilder epBuilder = new EndpointBuilder();
100 OpflexOverlayContextBuilder oocb = new OpflexOverlayContextBuilder();
101 oocb.setAgentId(this.agentId);
103 epBuilder.setTenant(this.tid)
104 .setEndpointGroup(this.egid)
105 .setL2Context(this.l2bdid)
107 .setMacAddress(this.mac)
108 .setTimestamp(this.timeout)
109 .addAugmentation(OpflexOverlayContext.class, oocb.build());
111 // TODO: add support for conditions
112 // epBuilder.setCondition(new List<ConditionName>());
114 return epBuilder.build();
118 * Create or update an L2 Endpoint in the Endpoint Registry
120 * @param wt The Write Transaction
123 public void put(WriteTransaction wt) {
126 this.iid = InstanceIdentifier.builder(Endpoints.class).child(Endpoint.class, ep.getKey()).build();
127 wt.put(LogicalDatastoreType.OPERATIONAL, iid, ep);
131 public void delete(WriteTransaction wt) {
134 this.iid = InstanceIdentifier.builder(Endpoints.class).child(Endpoint.class, ep.getKey()).build();
135 wt.delete(LogicalDatastoreType.OPERATIONAL, iid);
139 * Get/read an L2 endpoint in the registry, given a context
143 * @param rot The read transaction
146 public void read(ReadOnlyTransaction rot, ScheduledExecutorService executor) {
149 this.iid = InstanceIdentifier.builder(Endpoints.class).child(Endpoint.class, ep.getKey()).build();
151 ListenableFuture<Optional<Endpoint>> dao = rot.read(LogicalDatastoreType.OPERATIONAL, iid);
152 Futures.addCallback(dao, this, executor);
156 public void setCallback(EprOpCallback callback) {
161 public void onSuccess(final Optional<Endpoint> result) {
162 if (!result.isPresent()) {
164 * This EP doesn't exist in the registry. If
165 * all of the data store queries have been made,
166 * and we still don't have any EPs, then provide
178 public void onFailure(Throwable t) {