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.List;
12 import java.util.concurrent.ScheduledExecutorService;
14 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
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.L3ContextId;
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.Endpoints;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoint.fields.L3Address;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Builder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.OpflexOverlayContextL3;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.opflex.rev140528.OpflexOverlayContextL3Builder;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import com.google.common.base.Optional;
32 import com.google.common.util.concurrent.FutureCallback;
33 import com.google.common.util.concurrent.Futures;
34 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 L3 Endpoints.
42 public class L3EprOperation implements EprOperation, FutureCallback<Optional<EndpointL3>> {
44 private EprOpCallback cb;
45 private EndpointL3 ep;
46 private InstanceIdentifier<EndpointL3> iid;
48 private String agentId;
50 private EndpointGroupId egid;
51 private MacAddress mac;
52 private List<L3Address> l3al;
53 private L2BridgeDomainId l2bdid;
54 private L3ContextId l3cid;
58 public L3EprOperation(int prr) {
59 this.timeout = Long.valueOf(prr);
62 public L3EprOperation() {}
64 public void setAgentId(String agentId) {
65 this.agentId = agentId;
68 public void setTenantId(TenantId tid) {
72 public void setEndpointGroupId(EndpointGroupId egid) {
76 public void setContextId(L3ContextId l3cid) {
80 public void setL2BridgDomainId(L2BridgeDomainId l2bdid) {
84 public void setMacAddress(MacAddress mac) {
88 public void setIpAddress(IpAddress ip) {
92 public void setL3AddressList(List<L3Address> l3al) {
96 public void addL3Address(L3Address l3a) {
100 public EndpointL3 getEp() {
104 public void setEp(EndpointL3 ep) {
108 public EndpointL3 buildEp() {
109 EndpointL3Builder epBuilder = new EndpointL3Builder();
110 OpflexOverlayContextL3Builder oocb = new OpflexOverlayContextL3Builder();
111 oocb.setAgentId(this.agentId);
113 epBuilder.setTenant(this.tid)
114 .setEndpointGroup(this.egid)
115 .setL2Context(this.l2bdid)
116 .setL3Context(this.l3cid)
118 .setMacAddress(this.mac)
119 .setIpAddress(this.ip)
120 .setTimestamp(this.timeout)
121 .addAugmentation(OpflexOverlayContextL3.class, oocb.build());
123 // TODO: add support for conditions
124 // epBuilder.setCondition(new List<ConditionName>());
126 return epBuilder.build();
130 public void onSuccess(final Optional<EndpointL3> result) {
131 if (!result.isPresent()) {
133 * This EP doesn't exist in the registry. If
134 * all of the data store queries have been made,
135 * and we still don't have any EPs, then provide
147 public void onFailure(Throwable t) {
148 // TODO: implement another callback
152 public void put(WriteTransaction wt) {
154 this.iid = InstanceIdentifier.builder(Endpoints.class).child(EndpointL3.class, ep.getKey()).build();
155 wt.put(LogicalDatastoreType.OPERATIONAL, iid, ep);
159 public void delete(WriteTransaction wt) {
161 this.iid = InstanceIdentifier.builder(Endpoints.class).child(EndpointL3.class, ep.getKey()).build();
162 wt.delete(LogicalDatastoreType.OPERATIONAL, iid);
166 public void read(ReadOnlyTransaction rot, ScheduledExecutorService executor) {
168 this.iid = InstanceIdentifier.builder(Endpoints.class).child(EndpointL3.class, ep.getKey()).build();
170 ListenableFuture<Optional<EndpointL3>> dao = rot.read(LogicalDatastoreType.OPERATIONAL, iid);
171 Futures.addCallback(dao, this, executor);
176 public void setCallback(EprOpCallback callback) {