2 * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.netvirt.elan.utils;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Strings;
13 import com.google.common.collect.Lists;
14 import com.google.common.primitives.Ints;
15 import com.google.common.util.concurrent.CheckedFuture;
16 import com.google.common.util.concurrent.FutureCallback;
17 import com.google.common.util.concurrent.Futures;
18 import com.google.common.util.concurrent.ListenableFuture;
20 import java.math.BigInteger;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
28 import java.util.concurrent.ConcurrentHashMap;
29 import java.util.concurrent.ExecutionException;
30 import java.util.concurrent.Future;
32 import javax.annotation.Nonnull;
33 import javax.inject.Inject;
34 import javax.inject.Singleton;
35 import org.apache.commons.lang3.StringUtils;
36 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
37 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
38 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
39 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
40 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
41 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
42 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
43 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
44 import org.opendaylight.genius.interfacemanager.globals.InterfaceServiceUtil;
45 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
46 import org.opendaylight.genius.itm.globals.ITMConstants;
47 import org.opendaylight.genius.mdsalutil.ActionInfo;
48 import org.opendaylight.genius.mdsalutil.FlowEntity;
49 import org.opendaylight.genius.mdsalutil.FlowEntityBuilder;
50 import org.opendaylight.genius.mdsalutil.InstructionInfo;
51 import org.opendaylight.genius.mdsalutil.MDSALUtil;
52 import org.opendaylight.genius.mdsalutil.MDSALUtil.MdsalOp;
53 import org.opendaylight.genius.mdsalutil.MatchInfo;
54 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
55 import org.opendaylight.genius.mdsalutil.NWUtil;
56 import org.opendaylight.genius.mdsalutil.NwConstants;
57 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
58 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
59 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
60 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
61 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
62 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetSource;
63 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
64 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
65 import org.opendaylight.genius.mdsalutil.packet.ARP;
66 import org.opendaylight.genius.mdsalutil.packet.Ethernet;
67 import org.opendaylight.genius.mdsalutil.packet.IPv4;
68 import org.opendaylight.genius.utils.ServiceIndex;
69 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
70 import org.opendaylight.genius.utils.batching.ResourceBatchingManager.ShardResource;
71 import org.opendaylight.netvirt.elan.ElanException;
72 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
73 import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
74 import org.opendaylight.netvirt.elan.internal.ElanInterfaceManager;
75 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
76 import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
77 import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
78 import org.opendaylight.netvirt.elanmanager.api.ElanHelper;
79 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
80 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
81 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
82 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
86 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.IfIndexesInterfaceMap;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterfaceKey;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceOutput;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInput;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceInputBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEgressActionsForInterfaceOutput;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceBindings;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceTypeFlowBased;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.StypeOpenflow;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.StypeOpenflowBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfo;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.ServicesInfoKey;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServicesKey;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.ExternalTunnelList;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnel;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.external.tunnel.list.ExternalTunnelKey;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInput;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameInputBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetExternalTunnelInterfaceNameOutput;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInput;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameInputBuilder;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetTunnelInterfaceNameOutput;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveTerminatingServiceActionsInput;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.RemoveTerminatingServiceActionsInputBuilder;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInstance;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInstanceBuilder;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInterface;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInterface.EtreeInterfaceType;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeLeafTag;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeLeafTagName;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeLeafTagNameBuilder;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanDpnInterfaces;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanForwardingTables;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInstances;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaceForwardingEntries;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanState;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanTagNameMap;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.SegmentTypeFlat;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.SegmentTypeVlan;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.SegmentTypeVxlan;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMac;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan._interface.forwarding.entries.ElanInterfaceMacKey;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesList;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.ElanDpnInterfacesListKey;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfaces;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.dpn.interfaces.elan.dpn.interfaces.list.DpnInterfacesKey;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTable;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTableBuilder;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.forwarding.tables.MacTableKey;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceBuilder;
171 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.elan.instance.ElanSegments;
172 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
173 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey;
174 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries;
175 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntriesBuilder;
176 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntriesKey;
177 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.Elan;
178 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.ElanBuilder;
179 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.state.ElanKey;
180 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName;
181 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagNameBuilder;
182 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagNameKey;
183 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry;
184 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryBuilder;
185 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntryKey;
186 import org.opendaylight.yangtools.yang.binding.DataObject;
187 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
188 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
189 import org.opendaylight.yangtools.yang.common.RpcResult;
190 import org.slf4j.Logger;
191 import org.slf4j.LoggerFactory;
194 public class ElanUtils {
196 private static final Logger LOG = LoggerFactory.getLogger(ElanUtils.class);
198 private static final boolean SH_FLAG_SET = true;
199 private static final boolean SH_FLAG_UNSET = false;
201 private static Map<String, ElanInstance> elanInstanceLocalCache = new ConcurrentHashMap<>();
202 private static Map<String, ElanInterface> elanInterfaceLocalCache = new ConcurrentHashMap<>();
203 private static Map<String, Set<DpnInterfaces>> elanInstancToDpnsCache = new ConcurrentHashMap<>();
204 private static Map<String, Set<String>> elanInstanceToInterfacesCache = new ConcurrentHashMap<>();
206 private final DataBroker broker;
207 private final IMdsalApiManager mdsalManager;
208 private final ElanInstanceManager elanInstanceManager;
209 private final OdlInterfaceRpcService interfaceManagerRpcService;
210 private final ItmRpcService itmRpcService;
211 private final ElanL2GatewayUtils elanL2GatewayUtils;
212 private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
213 private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
214 private final IInterfaceManager interfaceManager;
215 private final ElanConfig elanConfig;
217 public static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
219 public void onSuccess(Void result) {
220 LOG.debug("Success in Datastore operation");
224 public void onFailure(Throwable error) {
225 LOG.error("Error in Datastore operation", error);
230 public ElanUtils(DataBroker dataBroker, IMdsalApiManager mdsalManager, ElanInstanceManager elanInstanceManager,
231 OdlInterfaceRpcService interfaceManagerRpcService, ItmRpcService itmRpcService,
232 ElanInterfaceManager elanInterfaceManager, ElanConfig elanConfig,
233 EntityOwnershipService entityOwnershipService, IInterfaceManager interfaceManager) {
234 this.broker = dataBroker;
235 this.mdsalManager = mdsalManager;
236 this.elanInstanceManager = elanInstanceManager;
237 this.interfaceManagerRpcService = interfaceManagerRpcService;
238 this.itmRpcService = itmRpcService;
239 this.interfaceManager = interfaceManager;
240 this.elanConfig = elanConfig;
242 elanL2GatewayMulticastUtils =
243 new ElanL2GatewayMulticastUtils(broker, elanInstanceManager, elanInterfaceManager, this);
244 elanL2GatewayUtils = new ElanL2GatewayUtils(broker, itmRpcService, this,
245 entityOwnershipService, elanL2GatewayMulticastUtils);
246 elanL2GatewayMulticastUtils.setEElanL2GatewayUtils(elanL2GatewayUtils);
247 l2GatewayConnectionUtils = new L2GatewayConnectionUtils(broker,
248 elanInstanceManager, entityOwnershipService, this);
251 public void close() {
252 elanL2GatewayUtils.close();
255 public ElanL2GatewayUtils getElanL2GatewayUtils() {
256 return elanL2GatewayUtils;
259 public ElanL2GatewayMulticastUtils getElanL2GatewayMulticastUtils() {
260 return elanL2GatewayMulticastUtils;
263 public L2GatewayConnectionUtils getL2GatewayConnectionUtils() {
264 return l2GatewayConnectionUtils;
267 public final Boolean isOpenStackVniSemanticsEnforced() {
268 return elanConfig.isOpenstackVniSemanticsEnforced();
271 public static void addElanInstanceIntoCache(String elanInstanceName, ElanInstance elanInstance) {
272 elanInstanceLocalCache.put(elanInstanceName, elanInstance);
275 public static void removeElanInstanceFromCache(String elanInstanceName) {
276 elanInstanceLocalCache.remove(elanInstanceName);
279 public static ElanInstance getElanInstanceFromCache(String elanInstanceName) {
280 return elanInstanceLocalCache.get(elanInstanceName);
283 public static Set<String> getAllElanNames() {
284 return elanInstanceLocalCache.keySet();
287 public static void addElanInterfaceIntoCache(String interfaceName, ElanInterface elanInterface) {
288 elanInterfaceLocalCache.put(interfaceName, elanInterface);
291 public static void removeElanInterfaceFromCache(String interfaceName) {
292 elanInterfaceLocalCache.remove(interfaceName);
295 public static ElanInterface getElanInterfaceFromCache(String interfaceName) {
296 return elanInterfaceLocalCache.get(interfaceName);
300 * Uses the IdManager to retrieve a brand new ElanTag.
306 * @return the integer
308 public static Long retrieveNewElanTag(IdManagerService idManager, String idKey) {
310 AllocateIdInput getIdInput = new AllocateIdInputBuilder().setPoolName(ElanConstants.ELAN_ID_POOL_NAME)
311 .setIdKey(idKey).build();
314 Future<RpcResult<AllocateIdOutput>> result = idManager.allocateId(getIdInput);
315 RpcResult<AllocateIdOutput> rpcResult = result.get();
316 if (rpcResult.isSuccessful()) {
317 return rpcResult.getResult().getIdValue();
319 LOG.warn("RPC Call to Allocate Id returned with Errors {}", rpcResult.getErrors());
321 } catch (InterruptedException | ExecutionException e) {
322 LOG.warn("Exception when Allocating Id", e);
327 public static void releaseId(IdManagerService idManager, String poolName, String idKey) {
328 ReleaseIdInput releaseIdInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
329 idManager.releaseId(releaseIdInput);
335 * @deprecated Consider using {@link #read2(LogicalDatastoreType, InstanceIdentifier)} with proper exception
339 @SuppressWarnings("checkstyle:IllegalCatch")
340 public <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
341 InstanceIdentifier<T> path) {
342 try (ReadOnlyTransaction tx = broker != null ? broker.newReadOnlyTransaction()
343 : this.broker.newReadOnlyTransaction()) {
344 return tx.read(datastoreType, path).get();
345 } catch (Exception e) {
346 throw new RuntimeException(e);
350 public <T extends DataObject> Optional<T> read2(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path)
351 throws ReadFailedException {
352 try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
353 CheckedFuture<Optional<T>, ReadFailedException> checkedFuture = tx.read(datastoreType, path);
354 return checkedFuture.checkedGet();
358 public static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType,
359 InstanceIdentifier<T> path) {
360 WriteTransaction tx = broker.newWriteOnlyTransaction();
361 tx.delete(datastoreType, path);
362 Futures.addCallback(tx.submit(), DEFAULT_CALLBACK);
365 public static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType,
366 InstanceIdentifier<T> path, FutureCallback<Void> callback) {
367 WriteTransaction tx = broker.newWriteOnlyTransaction();
368 tx.delete(datastoreType, path);
369 Futures.addCallback(tx.submit(), callback);
372 public static InstanceIdentifier<ElanInstance> getElanInstanceIdentifier() {
373 return InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class).build();
376 // elan-instances config container
377 public static ElanInstance getElanInstanceByName(DataBroker broker, String elanInstanceName) {
378 ElanInstance elanObj = getElanInstanceFromCache(elanInstanceName);
379 if (elanObj != null) {
382 InstanceIdentifier<ElanInstance> elanIdentifierId =
383 ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName);
384 return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
387 // elan-interfaces Config Container
388 public static ElanInterface getElanInterfaceByElanInterfaceName(DataBroker broker, String elanInterfaceName) {
389 ElanInterface elanInterfaceObj = getElanInterfaceFromCache(elanInterfaceName);
390 if (elanInterfaceObj != null) {
391 return elanInterfaceObj;
393 InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
394 return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
397 public static EtreeInterface getEtreeInterfaceByElanInterfaceName(DataBroker broker, String elanInterfaceName) {
398 ElanInterface elanInterface = getElanInterfaceByElanInterfaceName(broker, elanInterfaceName);
399 if (elanInterface == null) {
402 return elanInterface.getAugmentation(EtreeInterface.class);
406 public static InstanceIdentifier<ElanInterface> getElanInterfaceConfigurationDataPathId(String interfaceName) {
407 return InstanceIdentifier.builder(ElanInterfaces.class)
408 .child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).build();
411 // elan-state Operational container
412 public static Elan getElanByName(DataBroker broker, String elanInstanceName) {
413 InstanceIdentifier<Elan> elanIdentifier = getElanInstanceOperationalDataPath(elanInstanceName);
414 return MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanIdentifier).orNull();
417 public static InstanceIdentifier<Elan> getElanInstanceOperationalDataPath(String elanInstanceName) {
418 return InstanceIdentifier.builder(ElanState.class).child(Elan.class, new ElanKey(elanInstanceName)).build();
421 // grouping of forwarding-entries
422 public MacEntry getInterfaceMacEntriesOperationalDataPath(String interfaceName, PhysAddress physAddress) {
423 InstanceIdentifier<MacEntry> existingMacEntryId = getInterfaceMacEntriesIdentifierOperationalDataPath(
424 interfaceName, physAddress);
425 return read(broker, LogicalDatastoreType.OPERATIONAL, existingMacEntryId).orNull();
428 public MacEntry getInterfaceMacEntriesOperationalDataPathFromId(InstanceIdentifier identifier) {
429 Optional<MacEntry> existingInterfaceMacEntry = read(broker,
430 LogicalDatastoreType.OPERATIONAL, identifier);
431 return existingInterfaceMacEntry.orNull();
434 public static InstanceIdentifier<MacEntry> getInterfaceMacEntriesIdentifierOperationalDataPath(String interfaceName,
435 PhysAddress physAddress) {
436 return InstanceIdentifier.builder(ElanInterfaceForwardingEntries.class)
437 .child(ElanInterfaceMac.class, new ElanInterfaceMacKey(interfaceName))
438 .child(MacEntry.class, new MacEntryKey(physAddress)).build();
442 // elan-forwarding-tables Operational container
443 public Optional<MacEntry> getMacEntryForElanInstance(String elanName, PhysAddress physAddress) {
444 InstanceIdentifier<MacEntry> macId = getMacEntryOperationalDataPath(elanName, physAddress);
445 return read(broker, LogicalDatastoreType.OPERATIONAL, macId);
448 public MacEntry getMacEntryFromElanMacId(InstanceIdentifier identifier) {
449 Optional<MacEntry> existingInterfaceMacEntry = read(broker,
450 LogicalDatastoreType.OPERATIONAL, identifier);
451 return existingInterfaceMacEntry.orNull();
454 public static InstanceIdentifier<MacEntry> getMacEntryOperationalDataPath(String elanName,
455 PhysAddress physAddress) {
456 return InstanceIdentifier.builder(ElanForwardingTables.class).child(MacTable.class, new MacTableKey(elanName))
457 .child(MacEntry.class, new MacEntryKey(physAddress)).build();
460 public static InstanceIdentifier<MacTable> getElanMacTableOperationalDataPath(String elanName) {
461 return InstanceIdentifier.builder(ElanForwardingTables.class).child(MacTable.class, new MacTableKey(elanName))
465 // elan-interface-forwarding-entries Operational container
466 public ElanInterfaceMac getElanInterfaceMacByInterfaceName(String interfaceName) {
467 InstanceIdentifier<ElanInterfaceMac> elanInterfaceId = getElanInterfaceMacEntriesOperationalDataPath(
469 return read(broker, LogicalDatastoreType.OPERATIONAL, elanInterfaceId).orNull();
473 * Gets the elan interface mac addresses.
475 * @param interfaceName
477 * @return the elan interface mac addresses
479 public List<PhysAddress> getElanInterfaceMacAddresses(String interfaceName) {
480 List<PhysAddress> macAddresses = new ArrayList<>();
481 ElanInterfaceMac elanInterfaceMac = getElanInterfaceMacByInterfaceName(interfaceName);
482 if (elanInterfaceMac != null && elanInterfaceMac.getMacEntry() != null) {
483 List<MacEntry> macEntries = elanInterfaceMac.getMacEntry();
484 for (MacEntry macEntry : macEntries) {
485 macAddresses.add(macEntry.getMacAddress());
491 public static InstanceIdentifier<ElanInterfaceMac> getElanInterfaceMacEntriesOperationalDataPath(
492 String interfaceName) {
493 return InstanceIdentifier.builder(ElanInterfaceForwardingEntries.class)
494 .child(ElanInterfaceMac.class, new ElanInterfaceMacKey(interfaceName)).build();
498 * Returns the list of Interfaces that belong to an Elan on an specific DPN.
499 * Data retrieved from Elan's operational DS: elan-dpn-interfaces container
501 * @param elanInstanceName
502 * name of the Elan to which the interfaces must belong to
504 * Id of the DPN where the interfaces are located
505 * @return the elan interface Info
507 public DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId) {
508 InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
510 return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orNull();
514 * Returns the InstanceIdentifier that points to the Interfaces of an Elan
515 * in a given DPN in the Operational DS. Data retrieved from Elans's
516 * operational DS: dpn-interfaces list
518 * @param elanInstanceName
519 * name of the Elan to which the interfaces must belong to
521 * Id of the DPN where the interfaces are located
522 * @return the elan dpn interface
524 public static InstanceIdentifier<DpnInterfaces> getElanDpnInterfaceOperationalDataPath(String elanInstanceName,
526 return InstanceIdentifier.builder(ElanDpnInterfaces.class)
527 .child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName))
528 .child(DpnInterfaces.class, new DpnInterfacesKey(dpId)).build();
531 // elan-tag-name-map Operational Container
532 public ElanTagName getElanInfoByElanTag(long elanTag) {
533 InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
534 Optional<ElanTagName> existingElanInfo = read(broker,
535 LogicalDatastoreType.OPERATIONAL, elanId);
536 return existingElanInfo.orNull();
539 public EtreeLeafTagName getEtreeLeafTagByElanTag(long elanTag) {
540 InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
541 Optional<ElanTagName> existingElanInfo = read(broker,
542 LogicalDatastoreType.OPERATIONAL, elanId);
543 if (existingElanInfo.isPresent()) {
544 ElanTagName elanTagName = existingElanInfo.get();
545 return elanTagName.getAugmentation(EtreeLeafTagName.class);
550 public static InstanceIdentifier<ElanTagName> getElanInfoEntriesOperationalDataPath(long elanTag) {
551 return InstanceIdentifier.builder(ElanTagNameMap.class).child(ElanTagName.class, new ElanTagNameKey(elanTag))
555 // interface-index-tag operational container
556 public Optional<IfIndexInterface> getInterfaceInfoByInterfaceTag(long interfaceTag) {
557 InstanceIdentifier<IfIndexInterface> interfaceId = getInterfaceInfoEntriesOperationalDataPath(interfaceTag);
558 return read(broker, LogicalDatastoreType.OPERATIONAL, interfaceId);
561 public static InstanceIdentifier<IfIndexInterface> getInterfaceInfoEntriesOperationalDataPath(long interfaceTag) {
562 return InstanceIdentifier.builder(IfIndexesInterfaceMap.class)
563 .child(IfIndexInterface.class, new IfIndexInterfaceKey((int) interfaceTag)).build();
566 public static InstanceIdentifier<ElanDpnInterfacesList> getElanDpnOperationDataPath(String elanInstanceName) {
567 return InstanceIdentifier.builder(ElanDpnInterfaces.class)
568 .child(ElanDpnInterfacesList.class, new ElanDpnInterfacesListKey(elanInstanceName)).build();
571 public ElanDpnInterfacesList getElanDpnInterfacesList(String elanName) {
572 InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanName);
573 return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
576 public ElanDpnInterfaces getElanDpnInterfacesList() {
577 InstanceIdentifier<ElanDpnInterfaces> elanDpnInterfaceId = InstanceIdentifier.builder(ElanDpnInterfaces.class)
579 return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
583 * This method is useful get all ELAN participating CSS dpIds to install
584 * program remote dmac entries and updating remote bc groups for tor
587 * @param elanInstanceName
588 * the elan instance name
589 * @return list of dpIds
591 public List<BigInteger> getParticipatingDpnsInElanInstance(String elanInstanceName) {
592 List<BigInteger> dpIds = new ArrayList<>();
593 InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
594 Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
595 LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
596 if (!existingElanDpnInterfaces.isPresent()) {
599 List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().getDpnInterfaces();
600 for (DpnInterfaces dpnInterface : dpnInterfaces) {
601 dpIds.add(dpnInterface.getDpId());
607 * To check given dpId is already present in Elan instance. This can be used
608 * to program flow entry in external tunnel table when a new access port
609 * added for first time into the ELAN instance
613 * @param elanInstanceName
614 * the elan instance name
615 * @return true if dpId is already present, otherwise return false
617 public boolean isDpnAlreadyPresentInElanInstance(BigInteger dpId, String elanInstanceName) {
618 InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
619 Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
620 LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
621 if (!existingElanDpnInterfaces.isPresent()) {
624 List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().getDpnInterfaces();
625 for (DpnInterfaces dpnInterface : dpnInterfaces) {
626 if (dpnInterface.getDpId().equals(dpId)) {
633 public ElanForwardingTables getElanForwardingList() {
634 InstanceIdentifier<ElanForwardingTables> elanForwardingTableId = InstanceIdentifier
635 .builder(ElanForwardingTables.class).build();
636 return read(broker, LogicalDatastoreType.OPERATIONAL, elanForwardingTableId).orNull();
639 public static long getElanRemoteBroadCastGroupID(long elanTag) {
640 return ElanConstants.ELAN_GID_MIN + elanTag % ElanConstants.ELAN_GID_MIN * 2;
644 * Gets the elan mac table.
648 * @return the elan mac table
650 public MacTable getElanMacTable(String elanName) {
651 InstanceIdentifier<MacTable> elanMacTableId = getElanMacTableOperationalDataPath(elanName);
652 return read(broker, LogicalDatastoreType.OPERATIONAL, elanMacTableId).orNull();
655 public static long getElanLocalBCGId(long elanTag) {
656 return ElanConstants.ELAN_GID_MIN + (elanTag % ElanConstants.ELAN_GID_MIN * 2 - 1);
659 public static long getElanRemoteBCGId(long elanTag) {
660 return ElanConstants.ELAN_GID_MIN + elanTag % ElanConstants.ELAN_GID_MIN * 2;
663 public static long getEtreeLeafLocalBCGId(long etreeLeafTag) {
664 return ElanConstants.ELAN_GID_MIN + (etreeLeafTag % ElanConstants.ELAN_GID_MIN * 2 - 1);
667 public static long getEtreeLeafRemoteBCGId(long etreeLeafTag) {
668 return ElanConstants.ELAN_GID_MIN + etreeLeafTag % ElanConstants.ELAN_GID_MIN * 2;
671 public static BigInteger getElanMetadataLabel(long elanTag, boolean isSHFlagSet) {
672 int shBit = isSHFlagSet ? 1 : 0;
673 return BigInteger.valueOf(elanTag).shiftLeft(24).or(BigInteger.valueOf(shBit));
677 * Setting SMAC, DMAC, UDMAC in this DPN and optionally in other DPNs.
681 * @param interfaceInfo
687 * @param configureRemoteFlows
688 * true if remote dmac flows should be configured as well
689 * @param writeFlowGroupTx
691 * @throws ElanException in case of issues creating the flow objects
693 public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
694 long macTimeout, String macAddress, boolean configureRemoteFlows,
695 WriteTransaction writeFlowGroupTx) throws ElanException {
696 synchronized (getElanMacDPNKey(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
697 setupKnownSmacFlow(elanInfo, interfaceInfo, macTimeout, macAddress, mdsalManager,
699 setupOrigDmacFlows(elanInfo, interfaceInfo, macAddress, configureRemoteFlows, mdsalManager,
700 broker, writeFlowGroupTx);
704 public void setupDMacFlowOnRemoteDpn(ElanInstance elanInfo, InterfaceInfo interfaceInfo, BigInteger dstDpId,
705 String macAddress, WriteTransaction writeFlowTx) throws ElanException {
706 String elanInstanceName = elanInfo.getElanInstanceName();
707 setupRemoteDmacFlow(dstDpId, interfaceInfo.getDpId(), interfaceInfo.getInterfaceTag(), elanInfo.getElanTag(),
708 macAddress, elanInstanceName, writeFlowTx, interfaceInfo.getInterfaceName(), elanInfo);
709 LOG.info("Remote Dmac flow entry created for elan Name:{}, logical port Name:{} and"
710 + " mac address {} on dpn:{}", elanInstanceName, interfaceInfo.getPortName(),
711 macAddress, dstDpId);
715 * Inserts a Flow in SMAC table to state that the MAC has already been
718 private void setupKnownSmacFlow(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
719 String macAddress, IMdsalApiManager mdsalApiManager, WriteTransaction writeFlowGroupTx) {
720 FlowEntity flowEntity = buildKnownSmacFlow(elanInfo, interfaceInfo, macTimeout, macAddress);
721 mdsalApiManager.addFlowToTx(flowEntity, writeFlowGroupTx);
722 LOG.debug("Known Smac flow entry created for elan Name:{}, logical Interface port:{} and mac address:{}",
723 elanInfo.getElanInstanceName(), elanInfo.getDescription(), macAddress);
726 public FlowEntity buildKnownSmacFlow(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
728 int lportTag = interfaceInfo.getInterfaceTag();
729 // Matching metadata and eth_src fields
730 List<MatchInfo> mkMatches = new ArrayList<>();
731 mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanInfo.getElanTag(), lportTag),
732 ElanHelper.getElanMetadataMask()));
733 mkMatches.add(new MatchEthernetSource(new MacAddress(macAddress)));
734 List<InstructionInfo> mkInstructions = new ArrayList<>();
735 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
736 BigInteger dpId = interfaceInfo.getDpId();
737 long elanTag = getElanTag(broker, elanInfo, interfaceInfo);
738 return new FlowEntityBuilder()
740 .setTableId(NwConstants.ELAN_SMAC_TABLE)
741 .setFlowId(getKnownDynamicmacFlowRef(NwConstants.ELAN_SMAC_TABLE, dpId, lportTag, macAddress, elanTag))
743 .setFlowName(elanInfo.getDescription())
744 .setIdleTimeOut((int) macTimeout)
746 .setCookie(ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(elanTag)))
747 .setMatchInfoList(mkMatches)
748 .setInstructionInfoList(mkInstructions)
750 // If Mac timeout is 0, the flow won't be deleted automatically, so no need to get notified
751 .setSendFlowRemFlag(macTimeout != 0)
755 private static Long getElanTag(DataBroker broker, ElanInstance elanInfo, InterfaceInfo interfaceInfo) {
756 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceInfo.getInterfaceName());
757 if (etreeInterface == null || etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
758 return elanInfo.getElanTag();
760 EtreeInstance etreeInstance = elanInfo.getAugmentation(EtreeInstance.class);
761 if (etreeInstance == null) {
762 LOG.warn("EtreeInterface {} is connected to a non-Etree network: {}",
763 interfaceInfo.getInterfaceName(), elanInfo.getElanInstanceName());
764 return elanInfo.getElanTag();
766 return etreeInstance.getEtreeLeafTagVal().getValue();
772 * Installs a Flow in INTERNAL_TUNNEL_TABLE of the affected DPN that sends
773 * the packet through the specified interface if the tunnel_id matches the
774 * interface's lportTag.
776 * @param interfaceInfo
778 * @param mdsalApiManager
779 * the mdsal API manager
780 * @param writeFlowGroupTx
781 * the writeFLowGroup tx
783 public void setupTermDmacFlows(InterfaceInfo interfaceInfo, IMdsalApiManager mdsalApiManager,
784 WriteTransaction writeFlowGroupTx) {
785 BigInteger dpId = interfaceInfo.getDpId();
786 int lportTag = interfaceInfo.getInterfaceTag();
787 Flow flow = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
788 getIntTunnelTableFlowRef(NwConstants.INTERNAL_TUNNEL_TABLE, lportTag), 5,
789 String.format("%s:%d", "ITM Flow Entry ", lportTag), 0, 0,
790 ITMConstants.COOKIE_ITM.add(BigInteger.valueOf(lportTag)),
791 getTunnelIdMatchForFilterEqualsLPortTag(lportTag),
792 getInstructionsInPortForOutGroup(interfaceInfo.getInterfaceName()));
793 mdsalApiManager.addFlowToTx(dpId, flow, writeFlowGroupTx);
794 LOG.debug("Terminating service table flow entry created on dpn:{} for logical Interface port:{}", dpId,
795 interfaceInfo.getPortName());
799 * Constructs the FlowName for flows installed in the Internal Tunnel Table,
800 * consisting in tableId + elanTag.
806 * @return the Internal tunnel
808 public static String getIntTunnelTableFlowRef(short tableId, int elanTag) {
809 return new StringBuffer().append(tableId).append(elanTag).toString();
813 * Constructs the Matches that checks that the tunnel_id field contains a
817 * lportTag that must be checked against the tunnel_id field
818 * @return the list of match Info
820 public static List<MatchInfo> getTunnelIdMatchForFilterEqualsLPortTag(int lportTag) {
821 List<MatchInfo> mkMatches = new ArrayList<>();
823 mkMatches.add(new MatchTunnelId(BigInteger.valueOf(lportTag)));
828 * Constructs the Instructions that take the packet over a given interface.
831 * Name of the interface where the packet must be sent over. It
832 * can be a local interface or a tunnel interface (internal or
834 * @return the Instruction
836 public List<Instruction> getInstructionsInPortForOutGroup(String ifName) {
837 List<Instruction> mkInstructions = new ArrayList<>();
838 List<Action> actions = getEgressActionsForInterface(ifName, /* tunnelKey */ null);
840 mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
841 return mkInstructions;
845 * Returns the list of Actions to be taken when sending the packet through
846 * an Elan interface. Note that this interface can refer to an ElanInterface
847 * where the Elan VM is attached to a DPN or an ITM tunnel interface where
848 * Elan traffic can be sent through. In this latter case, the tunnelKey is
849 * mandatory and it can hold serviceId for internal tunnels or the VNI for
856 * @return the egress actions for interface
858 @SuppressWarnings("checkstyle:IllegalCatch")
859 public List<Action> getEgressActionsForInterface(String ifName, Long tunnelKey) {
860 List<Action> listAction = new ArrayList<>();
862 GetEgressActionsForInterfaceInput getEgressActionInput = new GetEgressActionsForInterfaceInputBuilder()
863 .setIntfName(ifName).setTunnelKey(tunnelKey).build();
864 Future<RpcResult<GetEgressActionsForInterfaceOutput>> result = interfaceManagerRpcService
865 .getEgressActionsForInterface(getEgressActionInput);
866 RpcResult<GetEgressActionsForInterfaceOutput> rpcResult = result.get();
867 if (!rpcResult.isSuccessful()) {
868 LOG.warn("RPC Call to Get egress actions for interface {} returned with Errors {}", ifName,
869 rpcResult.getErrors());
871 List<Action> actions = rpcResult.getResult().getAction();
872 listAction = actions;
874 } catch (Exception e) {
875 LOG.warn("Exception when egress actions for interface {}", ifName, e);
880 private void setupOrigDmacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
881 boolean configureRemoteFlows, IMdsalApiManager mdsalApiManager,
882 DataBroker broker, WriteTransaction writeFlowGroupTx)
883 throws ElanException {
884 BigInteger dpId = interfaceInfo.getDpId();
885 String ifName = interfaceInfo.getInterfaceName();
886 long ifTag = interfaceInfo.getInterfaceTag();
887 String elanInstanceName = elanInfo.getElanInstanceName();
889 Long elanTag = elanInfo.getElanTag();
891 setupLocalDmacFlow(elanTag, dpId, ifName, macAddress, elanInfo, mdsalApiManager, ifTag,
893 LOG.debug("Dmac flow entry created for elan Name:{}, logical port Name:{} mand mac address:{} "
894 + "on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, dpId);
896 if (!configureRemoteFlows) {
900 List<DpnInterfaces> elanDpns = getInvolvedDpnsInElan(elanInstanceName);
901 if (elanDpns == null) {
905 for (DpnInterfaces elanDpn : elanDpns) {
907 if (elanDpn.getDpId().equals(dpId)) {
911 // Check for the Remote DPN present in Inventory Manager
912 if (!isDpnPresent(elanDpn.getDpId())) {
916 // For remote DPNs a flow is needed to indicate that packets of this ELAN going to this MAC need to be
917 // forwarded through the appropriate ITM tunnel
918 setupRemoteDmacFlow(elanDpn.getDpId(), // srcDpn (the remote DPN in this case)
919 dpId, // dstDpn (the local DPN)
920 interfaceInfo.getInterfaceTag(), // lportTag of the local interface
921 elanTag, // identifier of the Elan
922 macAddress, // MAC to be programmed in remote DPN
923 elanInstanceName, writeFlowGroupTx, ifName, elanInfo
925 LOG.debug("Remote Dmac flow entry created for elan Name:{}, logical port Name:{} and mac address:{} on"
926 + " dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, elanDpn.getDpId());
929 // TODO: Make sure that the same is performed against the ElanDevices.
932 @SuppressWarnings("unchecked")
933 public List<DpnInterfaces> getInvolvedDpnsInElan(String elanName) {
934 List<DpnInterfaces> dpns = elanInstanceManager.getElanDPNByName(elanName);
936 return Collections.emptyList();
941 private void setupLocalDmacFlow(long elanTag, BigInteger dpId, String ifName, String macAddress,
942 ElanInstance elanInfo, IMdsalApiManager mdsalApiManager, long ifTag, WriteTransaction writeFlowGroupTx) {
943 Flow flowEntity = buildLocalDmacFlowEntry(elanTag, dpId, ifName, macAddress, elanInfo, ifTag);
944 mdsalApiManager.addFlowToTx(dpId, flowEntity, writeFlowGroupTx);
945 installEtreeLocalDmacFlow(elanTag, dpId, ifName, macAddress, elanInfo,
946 mdsalApiManager, ifTag, writeFlowGroupTx);
949 private void installEtreeLocalDmacFlow(long elanTag, BigInteger dpId, String ifName, String macAddress,
950 ElanInstance elanInfo, IMdsalApiManager mdsalApiManager, long ifTag, WriteTransaction writeFlowGroupTx) {
951 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, ifName);
952 if (etreeInterface != null) {
953 if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
954 EtreeLeafTagName etreeTagName = getEtreeLeafTagByElanTag(elanTag);
955 if (etreeTagName == null) {
956 LOG.warn("Interface {} seems like it belongs to Etree but etreeTagName from elanTag {} is null",
959 Flow flowEntity = buildLocalDmacFlowEntry(etreeTagName.getEtreeLeafTag().getValue(), dpId, ifName,
960 macAddress, elanInfo, ifTag);
961 mdsalApiManager.addFlowToTx(dpId, flowEntity, writeFlowGroupTx);
967 public static String getKnownDynamicmacFlowRef(short tableId, BigInteger dpId, long lporTag, String macAddress,
969 return new StringBuffer().append(tableId).append(elanTag).append(dpId).append(lporTag).append(macAddress)
973 public static String getKnownDynamicmacFlowRef(short tableId, BigInteger dpId, BigInteger remoteDpId,
974 String macAddress, long elanTag) {
975 return new StringBuffer().append(tableId).append(elanTag).append(dpId).append(remoteDpId).append(macAddress)
979 public static String getKnownDynamicmacFlowRef(short tableId, BigInteger dpId, String macAddress, long elanTag) {
980 return new StringBuffer().append(tableId).append(elanTag).append(dpId).append(macAddress).toString();
983 public static String getKnownDynamicmacFlowRef(short elanDmacTable, BigInteger dpId, String extDeviceNodeId,
984 String dstMacAddress, long elanTag, boolean shFlag) {
985 return new StringBuffer().append(elanDmacTable).append(elanTag).append(dpId).append(extDeviceNodeId)
986 .append(dstMacAddress).append(shFlag).toString();
990 * Builds the flow to be programmed in the DMAC table of the local DPN (that
991 * is, where the MAC is attached to). This flow consists in:
993 * <p>Match: + elanTag in metadata + packet goes to a MAC locally attached
994 * Actions: + optionally, pop-vlan + set-vlan-id + output to ifName's
1011 public Flow buildLocalDmacFlowEntry(long elanTag, BigInteger dpId, String ifName, String macAddress,
1012 ElanInstance elanInfo, long ifTag) {
1014 List<MatchInfo> mkMatches = new ArrayList<>();
1015 mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
1016 mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddress)));
1018 List<Instruction> mkInstructions = new ArrayList<>();
1019 List<Action> actions = getEgressActionsForInterface(ifName, /* tunnelKey */ null);
1020 mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
1021 Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
1022 getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, ifTag, macAddress, elanTag), 20,
1023 elanInfo.getElanInstanceName(), 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(
1024 BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
1029 public void setupRemoteDmacFlow(BigInteger srcDpId, BigInteger destDpId, int lportTag, long elanTag, String
1030 macAddress, String displayName, WriteTransaction writeFlowGroupTx, String interfaceName, ElanInstance
1031 elanInstance) throws ElanException {
1032 if (interfaceManager.isExternalInterface(interfaceName)) {
1033 LOG.debug("Ignoring install remote DMAC {} flow on provider interface {} elan {}",
1034 macAddress, interfaceName, elanInstance.getElanInstanceName());
1038 // if openstack-vni-semantics are enforced, segmentation ID is passed as network VNI for VxLAN based provider
1039 // networks, 0 otherwise
1040 long lportTagOrVni = !isOpenStackVniSemanticsEnforced() ? lportTag : ((isVxlan(elanInstance))
1041 ? elanInstance.getSegmentationId() : 0);
1042 flowEntity = buildRemoteDmacFlowEntry(srcDpId, destDpId, lportTagOrVni, elanTag, macAddress, displayName,
1044 mdsalManager.addFlowToTx(srcDpId, flowEntity, writeFlowGroupTx);
1045 setupEtreeRemoteDmacFlow(srcDpId, destDpId, lportTagOrVni, elanTag, macAddress, displayName, interfaceName,
1046 writeFlowGroupTx, elanInstance);
1049 private void setupEtreeRemoteDmacFlow(BigInteger srcDpId, BigInteger destDpId, long lportTagOrVni, long elanTag,
1050 String macAddress, String displayName, String interfaceName,
1051 WriteTransaction writeFlowGroupTx, ElanInstance elanInstance)
1052 throws ElanException {
1054 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
1055 if (etreeInterface != null) {
1056 if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
1057 EtreeLeafTagName etreeTagName = getEtreeLeafTagByElanTag(elanTag);
1058 if (etreeTagName == null) {
1059 LOG.warn("Interface " + interfaceName
1060 + " seems like it belongs to Etree but etreeTagName from elanTag " + elanTag + " is null.");
1062 flowEntity = buildRemoteDmacFlowEntry(srcDpId, destDpId, lportTagOrVni,
1063 etreeTagName.getEtreeLeafTag().getValue(), macAddress, displayName, elanInstance);
1064 mdsalManager.addFlowToTx(srcDpId, flowEntity, writeFlowGroupTx);
1071 * Builds a Flow to be programmed in a remote DPN's DMAC table. This flow
1072 * consists in: Match: + elanTag in packet's metadata + packet going to a
1073 * MAC known to be located in another DPN Actions: + set_tunnel_id
1074 * + output ITM internal tunnel interface with the other DPN
1080 * @param lportTagOrVni
1081 * lportTag or network VNI
1086 * @param displayName
1088 * @return the flow remote Dmac
1089 * @throws ElanException in case of issues creating the flow objects
1091 @SuppressWarnings("checkstyle:IllegalCatch")
1092 public Flow buildRemoteDmacFlowEntry(BigInteger srcDpId, BigInteger destDpId, long lportTagOrVni, long elanTag,
1093 String macAddress, String displayName, ElanInstance elanInstance) throws ElanException {
1094 List<MatchInfo> mkMatches = new ArrayList<>();
1095 mkMatches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
1096 mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddress)));
1098 List<Instruction> mkInstructions = new ArrayList<>();
1100 // List of Action for the provided Source and Destination DPIDs
1102 List<Action> actions = null;
1103 if (isVlan(elanInstance) || isFlat(elanInstance)) {
1104 String interfaceName = getExternalElanInterface(elanInstance.getElanInstanceName(), srcDpId);
1105 if (null == interfaceName) {
1106 LOG.error("buildRemoteDmacFlowEntry: Could not find interfaceName for {} {}", srcDpId,
1109 actions = getEgressActionsForInterface(interfaceName, null);
1110 } else if (isVxlan(elanInstance)) {
1111 actions = getInternalTunnelItmEgressAction(srcDpId, destDpId, lportTagOrVni);
1113 mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
1114 } catch (Exception e) {
1115 LOG.error("Could not get egress actions to add to flow for srcDpId=" + srcDpId + ", destDpId=" + destDpId
1116 + ", lportTag/VNI=" + lportTagOrVni, e);
1119 Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
1120 getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, srcDpId, destDpId, macAddress, elanTag),
1122 displayName, 0, /* idleTimeout */
1123 0, /* hardTimeout */
1124 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
1130 public void deleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, MacEntry macEntry,
1131 WriteTransaction deleteFlowGroupTx) {
1132 if (elanInfo == null || interfaceInfo == null) {
1135 String macAddress = macEntry.getMacAddress().getValue();
1136 synchronized (getElanMacDPNKey(elanInfo.getElanTag(), macAddress, interfaceInfo.getDpId())) {
1137 deleteMacFlows(elanInfo, interfaceInfo, macAddress, /* alsoDeleteSMAC */ true, deleteFlowGroupTx);
1141 public void deleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
1142 boolean deleteSmac, WriteTransaction deleteFlowGroupTx) {
1143 String elanInstanceName = elanInfo.getElanInstanceName();
1144 List<DpnInterfaces> remoteFEs = getInvolvedDpnsInElan(elanInstanceName);
1145 BigInteger srcdpId = interfaceInfo.getDpId();
1146 boolean isFlowsRemovedInSrcDpn = false;
1147 for (DpnInterfaces dpnInterface : remoteFEs) {
1148 Long elanTag = elanInfo.getElanTag();
1149 BigInteger dstDpId = dpnInterface.getDpId();
1150 if (executeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId,
1151 elanTag, dstDpId, deleteFlowGroupTx)) {
1152 isFlowsRemovedInSrcDpn = true;
1154 executeEtreeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId,
1155 elanTag, dstDpId, deleteFlowGroupTx);
1157 if (!isFlowsRemovedInSrcDpn) {
1158 deleteSmacAndDmacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, deleteFlowGroupTx);
1162 private void executeEtreeDeleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
1163 boolean deleteSmac, String elanInstanceName, BigInteger srcdpId, Long elanTag, BigInteger dstDpId,
1164 WriteTransaction deleteFlowGroupTx) {
1165 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
1166 if (etreeLeafTag != null) {
1167 executeDeleteMacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, elanInstanceName, srcdpId,
1168 etreeLeafTag.getEtreeLeafTag().getValue(), dstDpId, deleteFlowGroupTx);
1172 private boolean executeDeleteMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
1173 boolean deleteSmac, String elanInstanceName, BigInteger srcdpId, Long elanTag, BigInteger dstDpId,
1174 WriteTransaction deleteFlowGroupTx) {
1175 boolean isFlowsRemovedInSrcDpn = false;
1176 if (dstDpId.equals(srcdpId)) {
1177 isFlowsRemovedInSrcDpn = true;
1178 deleteSmacAndDmacFlows(elanInfo, interfaceInfo, macAddress, deleteSmac, deleteFlowGroupTx);
1179 } else if (isDpnPresent(dstDpId)) {
1181 .removeFlowToTx(dstDpId,
1182 MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, getKnownDynamicmacFlowRef(
1183 NwConstants.ELAN_DMAC_TABLE, dstDpId, srcdpId, macAddress, elanTag)),
1185 LOG.debug("Dmac flow entry deleted for elan:{}, logical interface port:{} and mac address:{} on dpn:{}",
1186 elanInstanceName, interfaceInfo.getPortName(), macAddress, dstDpId);
1188 return isFlowsRemovedInSrcDpn;
1191 private void deleteSmacAndDmacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, String macAddress,
1192 boolean deleteSmac, WriteTransaction deleteFlowGroupTx) {
1193 String elanInstanceName = elanInfo.getElanInstanceName();
1194 long ifTag = interfaceInfo.getInterfaceTag();
1195 BigInteger srcdpId = interfaceInfo.getDpId();
1196 Long elanTag = elanInfo.getElanTag();
1199 .removeFlowToTx(srcdpId,
1200 MDSALUtil.buildFlow(NwConstants.ELAN_SMAC_TABLE, getKnownDynamicmacFlowRef(
1201 NwConstants.ELAN_SMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)),
1204 mdsalManager.removeFlowToTx(srcdpId,
1205 MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE,
1206 getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)),
1208 LOG.debug("All the required flows deleted for elan:{}, logical Interface port:{} and MAC address:{} on dpn:{}",
1209 elanInstanceName, interfaceInfo.getPortName(), macAddress, srcdpId);
1213 * Updates the Elan information in the Operational DS. It also updates the
1214 * ElanInstance in the Config DS by setting the adquired elanTag.
1220 * @param elanInstanceAdded
1221 * the elan instance added
1222 * @param elanInterfaces
1223 * the elan interfaces
1227 public static void updateOperationalDataStore(DataBroker broker, IdManagerService idManager,
1228 ElanInstance elanInstanceAdded, List<String> elanInterfaces, WriteTransaction tx) {
1229 String elanInstanceName = elanInstanceAdded.getElanInstanceName();
1230 Long elanTag = elanInstanceAdded.getElanTag();
1231 if (elanTag == null || elanTag == 0L) {
1232 elanTag = retrieveNewElanTag(idManager, elanInstanceName);
1234 Elan elanInfo = new ElanBuilder().setName(elanInstanceName).setElanInterfaces(elanInterfaces)
1235 .setKey(new ElanKey(elanInstanceName)).build();
1237 // Add the ElanState in the elan-state operational data-store
1238 tx.put(LogicalDatastoreType.OPERATIONAL, getElanInstanceOperationalDataPath(elanInstanceName),
1241 // Add the ElanMacTable in the elan-mac-table operational data-store
1242 MacTable elanMacTable = new MacTableBuilder().setKey(new MacTableKey(elanInstanceName)).build();
1243 tx.put(LogicalDatastoreType.OPERATIONAL, getElanMacTableOperationalDataPath(elanInstanceName),
1244 elanMacTable, true);
1246 ElanTagNameBuilder elanTagNameBuilder = new ElanTagNameBuilder().setElanTag(elanTag)
1247 .setKey(new ElanTagNameKey(elanTag)).setName(elanInstanceName);
1248 long etreeLeafTag = -1;
1249 if (isEtreeInstance(elanInstanceAdded)) {
1250 etreeLeafTag = retrieveNewElanTag(idManager, elanInstanceName + ElanConstants.LEAVES_POSTFIX);
1251 EtreeLeafTagName etreeLeafTagName = new EtreeLeafTagNameBuilder()
1252 .setEtreeLeafTag(new EtreeLeafTag(etreeLeafTag)).build();
1253 elanTagNameBuilder.addAugmentation(EtreeLeafTagName.class, etreeLeafTagName);
1254 addTheLeafTagAsElanTag(broker, elanInstanceName, etreeLeafTag, tx);
1256 ElanTagName elanTagName = elanTagNameBuilder.build();
1258 // Add the ElanTag to ElanName in the elan-tag-name Operational
1260 tx.put(LogicalDatastoreType.OPERATIONAL,
1261 getElanInfoEntriesOperationalDataPath(elanTag), elanTagName);
1263 // Updates the ElanInstance Config DS by setting the just acquired
1265 ElanInstanceBuilder elanInstanceBuilder = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
1266 .setDescription(elanInstanceAdded.getDescription())
1267 .setMacTimeout(elanInstanceAdded.getMacTimeout() == null ? ElanConstants.DEFAULT_MAC_TIME_OUT
1268 : elanInstanceAdded.getMacTimeout())
1269 .setKey(elanInstanceAdded.getKey()).setElanTag(elanTag);
1270 if (isEtreeInstance(elanInstanceAdded)) {
1271 EtreeInstance etreeInstance = new EtreeInstanceBuilder().setEtreeLeafTagVal(new EtreeLeafTag(etreeLeafTag))
1273 elanInstanceBuilder.addAugmentation(EtreeInstance.class, etreeInstance);
1275 ElanInstance elanInstanceWithTag = elanInstanceBuilder.build();
1276 tx.merge(LogicalDatastoreType.CONFIGURATION, ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName),
1277 elanInstanceWithTag, true);
1280 private static void addTheLeafTagAsElanTag(DataBroker broker, String elanInstanceName, long etreeLeafTag,
1281 WriteTransaction tx) {
1282 ElanTagName etreeTagAsElanTag = new ElanTagNameBuilder().setElanTag(etreeLeafTag)
1283 .setKey(new ElanTagNameKey(etreeLeafTag)).setName(elanInstanceName).build();
1284 tx.put(LogicalDatastoreType.OPERATIONAL,
1285 getElanInfoEntriesOperationalDataPath(etreeLeafTag), etreeTagAsElanTag);
1288 private static boolean isEtreeInstance(ElanInstance elanInstanceAdded) {
1289 return elanInstanceAdded.getAugmentation(EtreeInstance.class) != null;
1292 public boolean isDpnPresent(BigInteger dpnId) {
1293 String dpn = String.format("%s:%s", "openflow", dpnId);
1294 NodeId nodeId = new NodeId(dpn);
1296 InstanceIdentifier<Node> node = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId))
1298 return read(broker, LogicalDatastoreType.CONFIGURATION, node).isPresent();
1301 public static ServicesInfo getServiceInfo(String elanInstanceName, long elanTag, String interfaceName) {
1302 int priority = ElanConstants.ELAN_SERVICE_PRIORITY;
1303 int instructionKey = 0;
1304 List<Instruction> instructions = new ArrayList<>();
1305 instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(ElanHelper.getElanMetadataLabel(elanTag),
1306 MetaDataUtil.METADATA_MASK_SERVICE, ++instructionKey));
1307 instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.ELAN_SMAC_TABLE, ++instructionKey));
1309 short serviceIndex = ServiceIndex.getIndex(NwConstants.ELAN_SERVICE_NAME, NwConstants.ELAN_SERVICE_INDEX);
1310 ServicesInfo serviceInfo = InterfaceServiceUtil.buildServiceInfo(
1311 String.format("%s.%s", elanInstanceName, interfaceName), serviceIndex, priority,
1312 NwConstants.COOKIE_ELAN_INGRESS_TABLE, instructions);
1316 public static <T extends DataObject> void syncWrite(DataBroker broker, LogicalDatastoreType datastoreType,
1317 InstanceIdentifier<T> path, T data) {
1318 WriteTransaction tx = broker.newWriteOnlyTransaction();
1319 tx.put(datastoreType, path, data, true);
1320 CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
1323 } catch (InterruptedException | ExecutionException e) {
1324 LOG.error("Error writing to datastore (path, data) : ({}, {})", path, data);
1325 throw new RuntimeException(e.getMessage());
1329 public static BoundServices getBoundServices(String serviceName, short servicePriority, int flowPriority,
1330 BigInteger cookie, List<Instruction> instructions) {
1331 StypeOpenflowBuilder augBuilder = new StypeOpenflowBuilder().setFlowCookie(cookie).setFlowPriority(flowPriority)
1332 .setInstruction(instructions);
1333 return new BoundServicesBuilder().setKey(new BoundServicesKey(servicePriority)).setServiceName(serviceName)
1334 .setServicePriority(servicePriority).setServiceType(ServiceTypeFlowBased.class)
1335 .addAugmentation(StypeOpenflow.class, augBuilder.build()).build();
1338 public static InstanceIdentifier<BoundServices> buildServiceId(String interfaceName, short serviceIndex) {
1339 return InstanceIdentifier.builder(ServiceBindings.class)
1340 .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, ServiceModeIngress.class))
1341 .child(BoundServices.class, new BoundServicesKey(serviceIndex)).build();
1345 * Builds the list of actions to be taken when sending the packet over a VxLan Tunnel Interface, such as setting
1346 * the network VNI in the tunnel_id field.
1348 * @param tunnelIfaceName
1349 * the tunnel iface name
1354 public List<Action> buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey) {
1355 if (tunnelIfaceName != null && !tunnelIfaceName.isEmpty()) {
1356 return buildItmEgressActions(tunnelIfaceName, tunnelKey);
1359 return Collections.emptyList();
1363 * Builds the list of actions to be taken when sending the packet over external port such as tunnel, physical
1366 * @param interfaceName
1367 * the interface name
1369 * can be VNI for VxLAN tunnel interfaces, Gre Key for GRE
1373 @SuppressWarnings("checkstyle:IllegalCatch")
1374 public List<Action> buildItmEgressActions(String interfaceName, Long tunnelKey) {
1375 List<Action> result = Collections.emptyList();
1377 GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder()
1378 .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
1380 Future<RpcResult<GetEgressActionsForInterfaceOutput>> egressActionsOutputFuture = interfaceManagerRpcService
1381 .getEgressActionsForInterface(getEgressActInput);
1382 if (egressActionsOutputFuture.get().isSuccessful()) {
1383 GetEgressActionsForInterfaceOutput egressActionsOutput = egressActionsOutputFuture.get().getResult();
1384 result = egressActionsOutput.getAction();
1386 } catch (Exception e) {
1387 LOG.error("Error in RPC call getEgressActionsForInterface {}", e);
1390 if (result == null || result.size() == 0) {
1391 LOG.warn("Could not build Egress actions for interface {} and tunnelId {}", interfaceName, tunnelKey);
1397 * Builds the list of actions to be taken when sending the packet over an
1398 * external VxLan tunnel interface, such as stamping the VNI on the VxLAN
1399 * header, setting the vlanId if it proceeds and output the packet over the
1403 * Dpn where the tunnelInterface is located
1405 * NodeId of the ExternalDevice where the packet must be sent to.
1407 * Vni to be stamped on the VxLAN Header.
1408 * @return the external itm egress action
1410 public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) {
1411 List<Action> result = Collections.emptyList();
1413 GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
1414 .setDestinationNode(torNode.getValue()).setSourceNode(srcDpnId.toString())
1415 .setTunnelType(TunnelTypeVxlan.class).build();
1416 Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService
1417 .getExternalTunnelInterfaceName(input);
1419 if (output.get().isSuccessful()) {
1420 GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
1421 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
1422 LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
1424 result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
1427 } catch (InterruptedException | ExecutionException e) {
1428 LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
1434 public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, String nexthopIP, long vni) {
1435 List<Action> result = Collections.emptyList();
1437 GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
1438 .setDestinationNode(nexthopIP).setSourceNode(srcDpnId.toString())
1439 .setTunnelType(TunnelTypeVxlan.class).build();
1440 Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService
1441 .getExternalTunnelInterfaceName(input);
1443 if (output.get().isSuccessful()) {
1444 GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
1445 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
1446 LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
1448 result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
1451 } catch (InterruptedException | ExecutionException e) {
1452 LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
1459 * Builds the list of actions to be taken when sending the packet over an internal VxLAN tunnel interface, such
1460 * as setting the serviceTag/segmentationID on the VNI field of the VxLAN header, setting the vlanId if it proceeds
1461 * and output the packet over the right port.
1463 * @param sourceDpnId
1464 * Dpn where the tunnelInterface is located
1465 * @param destinationDpnId
1466 * Dpn where the packet must be sent to. It is used here in order
1467 * to select the right tunnel interface.
1469 * Tunnel key to be sent on the VxLAN header.
1470 * @return the internal itm egress action
1472 public List<Action> getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId, long
1474 List<Action> result = Collections.emptyList();
1475 LOG.trace("In getInternalItmEgressAction Action source {}, destination {}, serviceTag/Vni {}", sourceDpnId,
1476 destinationDpnId, tunnelKey);
1477 Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
1478 GetTunnelInterfaceNameInput input = new GetTunnelInterfaceNameInputBuilder()
1479 .setDestinationDpid(destinationDpnId).setSourceDpid(sourceDpnId).setTunnelType(tunType).build();
1480 Future<RpcResult<GetTunnelInterfaceNameOutput>> output = itmRpcService.getTunnelInterfaceName(input);
1482 if (output.get().isSuccessful()) {
1483 GetTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
1484 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
1485 LOG.info("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
1486 result = buildTunnelItmEgressActions(tunnelIfaceName, tunnelKey);
1488 LOG.trace("Tunnel interface doesn't exist between srcDpId {} dstDpId {}", sourceDpnId,
1491 } catch (InterruptedException | ExecutionException e) {
1492 LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
1498 * Build the list of actions to be taken when sending the packet to external
1501 * @param interfaceName
1503 * @return the external port itm egress actions
1505 public List<Action> getExternalPortItmEgressAction(String interfaceName) {
1506 return buildItmEgressActions(interfaceName, null);
1509 public static List<MatchInfo> getTunnelMatchesForServiceId(int elanTag) {
1510 List<MatchInfo> mkMatches = new ArrayList<>();
1511 // Matching metadata
1512 mkMatches.add(new MatchTunnelId(BigInteger.valueOf(elanTag)));
1517 public void removeTerminatingServiceAction(BigInteger destDpId, int serviceId) {
1518 RemoveTerminatingServiceActionsInput input = new RemoveTerminatingServiceActionsInputBuilder()
1519 .setDpnId(destDpId).setServiceId(serviceId).build();
1520 Future<RpcResult<Void>> futureObject = itmRpcService.removeTerminatingServiceActions(input);
1522 RpcResult<Void> result = futureObject.get();
1523 if (result.isSuccessful()) {
1524 LOG.debug("Successfully completed removeTerminatingServiceActions for ELAN with serviceId {} on "
1525 + "dpn {}", serviceId, destDpId);
1527 LOG.debug("Failure in removeTerminatingServiceAction RPC call for ELAN with serviceId {} on "
1528 + "dpn {}", serviceId, destDpId);
1530 } catch (InterruptedException | ExecutionException e) {
1531 LOG.error("Error in RPC call removeTerminatingServiceActions for ELAN with serviceId {} on "
1532 + "dpn {}: {}", serviceId, destDpId, e);
1537 * Gets the external tunnel.
1539 * @param sourceDevice
1541 * @param destinationDevice
1542 * the destination device
1543 * @param datastoreType
1544 * the datastore type
1545 * @return the external tunnel
1547 public ExternalTunnel getExternalTunnel(String sourceDevice, String destinationDevice,
1548 LogicalDatastoreType datastoreType) {
1549 Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
1550 InstanceIdentifier<ExternalTunnel> iid = InstanceIdentifier.builder(ExternalTunnelList.class)
1551 .child(ExternalTunnel.class, new ExternalTunnelKey(destinationDevice, sourceDevice, tunType)).build();
1552 return read(broker, datastoreType, iid).orNull();
1556 * Gets the external tunnel.
1558 * @param interfaceName
1559 * the interface name
1560 * @param datastoreType
1561 * the datastore type
1562 * @return the external tunnel
1564 public ExternalTunnel getExternalTunnel(String interfaceName, LogicalDatastoreType datastoreType) {
1565 ExternalTunnel externalTunnel = null;
1566 List<ExternalTunnel> externalTunnels = getAllExternalTunnels(datastoreType);
1567 for (ExternalTunnel tunnel : externalTunnels) {
1568 if (StringUtils.equalsIgnoreCase(interfaceName, tunnel.getTunnelInterfaceName())) {
1569 externalTunnel = tunnel;
1573 return externalTunnel;
1577 * Gets the all external tunnels.
1579 * @param datastoreType
1580 * the data store type
1581 * @return the all external tunnels
1583 public List<ExternalTunnel> getAllExternalTunnels(LogicalDatastoreType datastoreType) {
1584 InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
1585 return read(broker, datastoreType, iid).transform(ExternalTunnelList::getExternalTunnel).or(
1586 Collections.emptyList());
1590 * Installs a Flow in the specified DPN's DMAC table. The flow is for a MAC
1591 * that is connected remotely in an External Device (TOR) and that is
1592 * accessible through an external tunnel. It also installs the flow for
1593 * dropping the packet if it came over an ITM tunnel (that is, if the
1594 * Split-Horizon flag is set)
1597 * Id of the DPN where the flow must be installed
1598 * @param extDeviceNodeId
1599 * the ext device node id
1606 * @param displayName
1608 * @param interfaceName
1609 * the interface name
1611 * @return the dmac flows
1612 * @throws ElanException in case of issues creating the flow objects
1614 public List<ListenableFuture<Void>> installDmacFlowsToExternalRemoteMac(BigInteger dpnId,
1615 String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
1616 String interfaceName) throws ElanException {
1617 List<ListenableFuture<Void>> futures = new ArrayList<>();
1618 synchronized (getElanMacDPNKey(elanTag, macAddress, dpnId)) {
1619 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
1621 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
1623 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress);
1624 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(dropFlow, dpnId),
1626 installEtreeDmacFlowsToExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress, displayName,
1627 interfaceName, futures);
1632 private void installEtreeDmacFlowsToExternalRemoteMac(BigInteger dpnId, String extDeviceNodeId, Long elanTag,
1633 Long vni, String macAddress, String displayName, String interfaceName,
1634 List<ListenableFuture<Void>> futures) throws ElanException {
1635 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
1636 if (etreeLeafTag != null) {
1637 buildEtreeDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress, futures,
1639 buildEtreeDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, vni, macAddress, displayName, interfaceName,
1640 futures, etreeLeafTag);
1644 private void buildEtreeDmacFlowForExternalRemoteMac(BigInteger dpnId, String extDeviceNodeId, Long vni,
1645 String macAddress, String displayName, String interfaceName, List<ListenableFuture<Void>> futures,
1646 EtreeLeafTagName etreeLeafTag) throws ElanException {
1647 boolean isRoot = false;
1648 if (interfaceName == null) {
1651 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
1652 if (etreeInterface != null) {
1653 if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
1659 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId,
1660 etreeLeafTag.getEtreeLeafTag().getValue(), vni, macAddress, displayName);
1661 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
1665 private void buildEtreeDmacFlowDropIfPacketComingFromTunnel(BigInteger dpnId, String extDeviceNodeId,
1666 Long elanTag, String macAddress, List<ListenableFuture<Void>> futures, EtreeLeafTagName etreeLeafTag) {
1667 if (etreeLeafTag != null) {
1668 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId,
1669 etreeLeafTag.getEtreeLeafTag().getValue(), macAddress);
1670 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(dropFlow, dpnId),
1675 public static List<MatchInfo> buildMatchesForElanTagShFlagAndDstMac(long elanTag, boolean shFlag, String macAddr) {
1676 List<MatchInfo> mkMatches = new ArrayList<>();
1678 new MatchMetadata(getElanMetadataLabel(elanTag, shFlag), MetaDataUtil.METADATA_MASK_SERVICE_SH_FLAG));
1679 mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddr)));
1684 * Builds a Flow to be programmed in a DPN's DMAC table. This method must be
1685 * used when the MAC is located in an External Device (TOR). The flow
1686 * matches on the specified MAC and 1) sends the packet over the CSS-TOR
1687 * tunnel if SHFlag is not set, or 2) drops it if SHFlag is set (what means
1688 * the packet came from an external tunnel)
1691 * DPN whose DMAC table is going to be modified
1692 * @param extDeviceNodeId
1693 * Hwvtep node where the mac is attached to
1695 * ElanId to which the MAC is being added to
1698 * @param dstMacAddress
1699 * The mac address to be programmed
1700 * @param displayName
1703 * @throws ElanException in case of issues creating the flow objects
1705 @SuppressWarnings("checkstyle:IllegalCatch")
1706 public Flow buildDmacFlowForExternalRemoteMac(BigInteger dpId, String extDeviceNodeId, long elanTag,
1707 Long vni, String dstMacAddress, String displayName) throws ElanException {
1708 List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */ false, dstMacAddress);
1709 List<Instruction> mkInstructions = new ArrayList<>();
1711 List<Action> actions = getExternalTunnelItmEgressAction(dpId, new NodeId(extDeviceNodeId), vni);
1712 mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
1713 } catch (Exception e) {
1714 LOG.error("Could not get Egress Actions for DpId=" + dpId + ", externalNode=" + extDeviceNodeId, e);
1717 Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
1718 getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, dstMacAddress, elanTag,
1721 displayName, 0, /* idleTimeout */
1722 0, /* hardTimeout */
1723 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
1729 * Builds the flow that drops the packet if it came through an external
1730 * tunnel, that is, if the Split-Horizon flag is set.
1733 * DPN whose DMAC table is going to be modified
1734 * @param extDeviceNodeId
1735 * Hwvtep node where the mac is attached to
1737 * ElanId to which the MAC is being added to
1738 * @param dstMacAddress
1739 * The mac address to be programmed
1741 private static Flow buildDmacFlowDropIfPacketComingFromTunnel(BigInteger dpnId, String extDeviceNodeId,
1742 Long elanTag, String dstMacAddress) {
1743 List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, SH_FLAG_SET, dstMacAddress);
1744 List<Instruction> mkInstructions = MDSALUtil.buildInstructionsDrop();
1745 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpnId, extDeviceNodeId, dstMacAddress,
1747 Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE, flowId, 20, /* prio */
1748 "Drop", 0, /* idleTimeout */
1749 0, /* hardTimeout */
1750 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
1755 private static String getDmacDropFlowId(Long elanTag, String dstMacAddress) {
1756 return new StringBuilder(NwConstants.ELAN_DMAC_TABLE).append(elanTag).append(dstMacAddress).append("Drop")
1761 * Installs or removes flows in DMAC table for MACs that are/were located in
1762 * an external Elan Device.
1765 * Id of the DPN where the DMAC table is going to be modified
1767 * Id of the External Device where the MAC is located
1771 * VNI of the LogicalSwitch to which the MAC belongs to, and that
1772 * is associated with the ELAN
1775 * @param elanInstanceName
1776 * the elan instance name
1777 * @param addOrRemove
1778 * Indicates if flows must be installed or removed.
1779 * @param interfaceName
1780 * the interface name
1781 * @throws ElanException in case of issues creating the flow objects
1782 * @see org.opendaylight.genius.mdsalutil.MDSALUtil.MdsalOp
1784 public void setupDmacFlowsToExternalRemoteMac(BigInteger dpId, String extNodeId, Long elanTag, Long vni,
1785 String macAddress, String elanInstanceName, MdsalOp addOrRemove, String interfaceName)
1786 throws ElanException {
1787 if (addOrRemove == MdsalOp.CREATION_OP) {
1788 installDmacFlowsToExternalRemoteMac(dpId, extNodeId, elanTag, vni, macAddress, elanInstanceName,
1790 } else if (addOrRemove == MdsalOp.REMOVAL_OP) {
1791 deleteDmacFlowsToExternalMac(elanTag, dpId, extNodeId, macAddress);
1796 * Delete dmac flows to external mac.
1802 * @param extDeviceNodeId
1803 * the ext device node id
1804 * @param macToRemove
1808 public List<ListenableFuture<Void>> deleteDmacFlowsToExternalMac(long elanTag, BigInteger dpId,
1809 String extDeviceNodeId, String macToRemove) {
1810 List<ListenableFuture<Void>> futures = new ArrayList<>();
1811 synchronized (getElanMacDPNKey(elanTag, macToRemove, dpId)) {
1812 // Removing the flows that sends the packet on an external tunnel
1813 removeFlowThatSendsThePacketOnAnExternalTunnel(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
1815 // And now removing the drop flow
1816 removeTheDropFlow(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
1818 deleteEtreeDmacFlowsToExternalMac(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
1823 private void deleteEtreeDmacFlowsToExternalMac(long elanTag, BigInteger dpId, String extDeviceNodeId,
1824 String macToRemove, List<ListenableFuture<Void>> futures) {
1825 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
1826 if (etreeLeafTag != null) {
1827 removeFlowThatSendsThePacketOnAnExternalTunnel(etreeLeafTag.getEtreeLeafTag().getValue(), dpId,
1828 extDeviceNodeId, macToRemove, futures);
1829 removeTheDropFlow(etreeLeafTag.getEtreeLeafTag().getValue(), dpId, extDeviceNodeId, macToRemove, futures);
1833 private void removeTheDropFlow(long elanTag, BigInteger dpId, String extDeviceNodeId, String macToRemove,
1834 List<ListenableFuture<Void>> futures) {
1835 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, macToRemove,
1837 Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
1838 ResourceBatchingManager.getInstance().delete(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flowToRemove, dpId));
1841 private void removeFlowThatSendsThePacketOnAnExternalTunnel(long elanTag, BigInteger dpId,
1842 String extDeviceNodeId, String macToRemove, List<ListenableFuture<Void>> futures) {
1843 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, macToRemove,
1845 Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
1846 ResourceBatchingManager.getInstance().delete(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flowToRemove, dpId));
1850 * Gets the dpid from interface.
1852 * @param interfaceName
1853 * the interface name
1854 * @return the dpid from interface
1856 public BigInteger getDpidFromInterface(String interfaceName) {
1857 BigInteger dpId = null;
1858 Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService
1859 .getDpidFromInterface(new GetDpidFromInterfaceInputBuilder().setIntfName(interfaceName).build());
1861 RpcResult<GetDpidFromInterfaceOutput> rpcResult = output.get();
1862 if (rpcResult.isSuccessful()) {
1863 dpId = rpcResult.getResult().getDpid();
1865 } catch (NullPointerException | InterruptedException | ExecutionException e) {
1866 LOG.error("Failed to get the DPN ID: {} for interface {}: {} ", dpId, interfaceName, e);
1872 * Checks if is interface operational.
1874 * @param interfaceName
1875 * the interface name
1878 * @return true, if is interface operational
1880 public static boolean isInterfaceOperational(String interfaceName, DataBroker dataBroker) {
1881 if (StringUtils.isBlank(interfaceName)) {
1884 Interface ifState = getInterfaceStateFromOperDS(interfaceName, dataBroker);
1885 if (ifState == null) {
1888 return ifState.getOperStatus() == OperStatus.Up && ifState.getAdminStatus() == AdminStatus.Up;
1892 * Gets the interface state from operational ds.
1894 * @param interfaceName
1895 * the interface name
1898 * @return the interface state from oper ds
1900 public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1901 .ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS(
1902 String interfaceName, DataBroker dataBroker) {
1903 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1904 .ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = createInterfaceStateInstanceIdentifier(
1906 return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId).orNull();
1910 * Creates the interface state instance identifier.
1912 * @param interfaceName
1913 * the interface name
1914 * @return the instance identifier
1916 public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1917 .ietf.interfaces.rev140508.interfaces.state.Interface> createInterfaceStateInstanceIdentifier(
1918 String interfaceName) {
1919 InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1920 .ietf.interfaces.rev140508.interfaces.state.Interface> idBuilder = InstanceIdentifier
1921 .builder(InterfacesState.class)
1922 .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1923 .ietf.interfaces.rev140508.interfaces.state.Interface.class,
1924 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1925 .ietf.interfaces.rev140508.interfaces.state.InterfaceKey(
1927 return idBuilder.build();
1930 public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
1931 WriteTransaction tx) {
1932 CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
1935 } catch (InterruptedException | ExecutionException e) {
1936 LOG.error("Error writing to datastore {}", e);
1941 public static boolean isVxlanNetwork(DataBroker broker, String elanInstanceName) {
1942 ElanInstance elanInstance = getElanInstanceByName(broker, elanInstanceName);
1943 return (elanInstance != null && isVxlan(elanInstance));
1946 public static boolean isVxlan(ElanInstance elanInstance) {
1947 return elanInstance != null && elanInstance.getSegmentType() != null
1948 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1949 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
1952 private static boolean isVxlanSegment(ElanInstance elanInstance) {
1953 if (elanInstance != null) {
1954 List<ElanSegments> elanSegments = elanInstance.getElanSegments();
1955 if (elanSegments != null) {
1956 for (ElanSegments segment : elanSegments) {
1957 if (segment != null && segment.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1958 && segment.getSegmentationId() != null
1959 && segment.getSegmentationId().longValue() != 0) {
1968 public static boolean isVxlanNetworkOrVxlanSegment(ElanInstance elanInstance) {
1969 return isVxlan(elanInstance) || isVxlanSegment(elanInstance);
1972 public static Long getVxlanSegmentationId(ElanInstance elanInstance) {
1973 Long segmentationId = 0L;
1975 if (elanInstance != null && elanInstance.getSegmentType() != null
1976 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1977 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId().longValue() != 0) {
1978 segmentationId = elanInstance.getSegmentationId();
1980 for (ElanSegments segment: elanInstance.getElanSegments()) {
1981 if (segment != null && segment.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1982 && segment.getSegmentationId() != null
1983 && segment.getSegmentationId().longValue() != 0) {
1984 segmentationId = segment.getSegmentationId();
1988 return segmentationId;
1991 public static boolean isVlan(ElanInstance elanInstance) {
1992 return elanInstance != null && elanInstance.getSegmentType() != null
1993 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVlan.class)
1994 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
1997 public static boolean isFlat(ElanInstance elanInstance) {
1998 return elanInstance != null && elanInstance.getSegmentType() != null
1999 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeFlat.class);
2002 public void handleDmacRedirectToDispatcherFlows(Long elanTag, String displayName,
2003 String macAddress, int addOrRemove, List<BigInteger> dpnIds) {
2004 for (BigInteger dpId : dpnIds) {
2005 if (addOrRemove == NwConstants.ADD_FLOW) {
2006 WriteTransaction writeTx = broker.newWriteOnlyTransaction();
2007 mdsalManager.addFlowToTx(buildDmacRedirectToDispatcherFlow(dpId, macAddress, displayName, elanTag),
2011 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, macAddress, elanTag);
2012 mdsalManager.removeFlow(dpId, MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, flowId));
2017 public static FlowEntity buildDmacRedirectToDispatcherFlow(BigInteger dpId, String dstMacAddress,
2018 String displayName, long elanTag) {
2019 List<MatchInfo> matches = new ArrayList<>();
2020 matches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
2021 matches.add(new MatchEthernetDestination(new MacAddress(dstMacAddress)));
2022 List<InstructionInfo> instructions = new ArrayList<>();
2023 List<ActionInfo> actions = new ArrayList<>();
2024 actions.add(new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
2026 instructions.add(new InstructionApplyActions(actions));
2027 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, dstMacAddress, elanTag);
2028 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 20, displayName, 0, 0,
2029 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)),
2030 matches, instructions);
2035 * Add Mac Address to ElanInterfaceForwardingEntries and ElanForwardingTables
2036 * Install SMAC and DMAC flows.
2038 public void addMacEntryToDsAndSetupFlows(IInterfaceManager interfaceManager, String interfaceName,
2039 String macAddress, String elanName, WriteTransaction tx, WriteTransaction flowWritetx, int macTimeOut)
2040 throws ElanException {
2041 LOG.trace("Adding mac address {} and interface name {} to ElanInterfaceForwardingEntries and "
2042 + "ElanForwardingTables DS", macAddress, interfaceName);
2043 BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
2044 PhysAddress physAddress = new PhysAddress(macAddress);
2045 MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress)
2046 .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
2047 .setIsStaticAddress(false).build();
2048 InstanceIdentifier<MacEntry> macEntryId = ElanUtils
2049 .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
2050 tx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
2051 InstanceIdentifier<MacEntry> elanMacEntryId = ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
2052 tx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
2053 ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
2054 setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress, true,
2059 * Remove Mac Address from ElanInterfaceForwardingEntries and ElanForwardingTables
2060 * Remove SMAC and DMAC flows.
2062 public void deleteMacEntryFromDsAndRemoveFlows(IInterfaceManager interfaceManager, String interfaceName,
2063 String macAddress, String elanName, WriteTransaction tx, WriteTransaction deleteFlowTx) {
2064 LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries "
2065 + "and ElanForwardingTables DS", macAddress, interfaceName);
2066 PhysAddress physAddress = new PhysAddress(macAddress);
2067 MacEntry macEntry = getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
2068 InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
2069 if (macEntry != null && interfaceInfo != null) {
2070 deleteMacFlows(ElanUtils.getElanInstanceByName(broker, elanName), interfaceInfo, macEntry, deleteFlowTx);
2072 tx.delete(LogicalDatastoreType.OPERATIONAL,
2073 ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
2074 tx.delete(LogicalDatastoreType.OPERATIONAL,
2075 ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
2078 public String getExternalElanInterface(String elanInstanceName, BigInteger dpnId) {
2079 DpnInterfaces dpnInterfaces = getElanInterfaceInfoByElanDpn(elanInstanceName, dpnId);
2080 if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null) {
2081 LOG.trace("Elan {} does not have interfaces in DPN {}", elanInstanceName, dpnId);
2085 for (String dpnInterface : dpnInterfaces.getInterfaces()) {
2086 if (interfaceManager.isExternalInterface(dpnInterface)) {
2087 return dpnInterface;
2091 LOG.trace("Elan {} does not have any external interace attached to DPN {}", elanInstanceName, dpnId);
2095 public static String getElanMacDPNKey(long elanTag, String macAddress, BigInteger dpnId) {
2096 String elanMacDmacDpnKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag + "DPN_ID-" + dpnId;
2097 return elanMacDmacDpnKey.intern();
2100 public static String getElanMacKey(long elanTag, String macAddress) {
2101 String elanMacKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag;
2102 return elanMacKey.intern();
2106 public static void addToListenableFutureIfTxException(RuntimeException exception,
2107 List<ListenableFuture<Void>> futures) {
2108 Throwable cause = exception.getCause();
2109 if (cause != null && cause instanceof TransactionCommitFailedException) {
2110 futures.add(Futures.immediateFailedCheckedFuture((TransactionCommitFailedException) cause));
2114 public static List<PhysAddress> getPhysAddress(List<String> macAddress) {
2115 Preconditions.checkNotNull(macAddress, "macAddress cannot be null");
2116 List<PhysAddress> physAddresses = new ArrayList<>();
2117 for (String mac : macAddress) {
2118 physAddresses.add(new PhysAddress(mac));
2120 return physAddresses;
2123 public static List<StaticMacEntries> getStaticMacEntries(List<String> staticMacAddresses) {
2124 if (isEmpty(staticMacAddresses)) {
2125 return Collections.EMPTY_LIST;
2127 StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
2128 List<StaticMacEntries> staticMacEntries = new ArrayList<>();
2129 List<PhysAddress> physAddressList = getPhysAddress(staticMacAddresses);
2130 for (PhysAddress physAddress : physAddressList) {
2131 staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
2133 return staticMacEntries;
2136 public static InstanceIdentifier<StaticMacEntries> getStaticMacEntriesCfgDataPathIdentifier(String interfaceName,
2137 String macAddress) {
2138 return InstanceIdentifier.builder(ElanInterfaces.class)
2139 .child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).child(StaticMacEntries.class,
2140 new StaticMacEntriesKey(new PhysAddress(macAddress))).build();
2143 public static List<StaticMacEntries> getDeletedEntries(List<StaticMacEntries> originalStaticMacEntries,
2144 List<StaticMacEntries> updatedStaticMacEntries) {
2145 if (isEmpty(originalStaticMacEntries)) {
2146 return Collections.EMPTY_LIST;
2148 List<StaticMacEntries> deleted = Lists.newArrayList(originalStaticMacEntries);
2149 if (isNotEmpty(updatedStaticMacEntries)) {
2150 deleted.removeAll(updatedStaticMacEntries);
2155 public static <T> List<T> diffOf(List<T> orig, List<T> updated) {
2156 if (isEmpty(orig)) {
2157 return Collections.EMPTY_LIST;
2159 List<T> diff = Lists.newArrayList(orig);
2160 if (isNotEmpty(updated)) {
2161 diff.removeAll(updated);
2166 public static void segregateToBeDeletedAndAddEntries(List<StaticMacEntries> originalStaticMacEntries,
2167 List<StaticMacEntries> updatedStaticMacEntries) {
2168 if (isNotEmpty(updatedStaticMacEntries)) {
2169 List<StaticMacEntries> existingClonedStaticMacEntries = new ArrayList<>();
2170 if (isNotEmpty(originalStaticMacEntries)) {
2171 existingClonedStaticMacEntries.addAll(0, originalStaticMacEntries);
2172 originalStaticMacEntries.removeAll(updatedStaticMacEntries);
2173 updatedStaticMacEntries.removeAll(existingClonedStaticMacEntries);
2178 public static boolean isEmpty(Collection collection) {
2179 return collection == null || collection.isEmpty();
2182 public static boolean isNotEmpty(Collection collection) {
2183 return !isEmpty(collection);
2186 public static void setElanInstancToDpnsCache(Map<String, Set<DpnInterfaces>> elanInstancToDpnsCache) {
2187 ElanUtils.elanInstancToDpnsCache = elanInstancToDpnsCache;
2190 public static Set<DpnInterfaces> getElanInvolvedDPNsFromCache(String elanName) {
2191 return elanInstancToDpnsCache.get(elanName);
2194 public static void addDPNInterfaceToElanInCache(String elanName, DpnInterfaces dpnInterfaces) {
2195 elanInstancToDpnsCache.computeIfAbsent(elanName, key -> new HashSet<>()).add(dpnInterfaces);
2198 public static void removeDPNInterfaceFromElanInCache(String elanName, DpnInterfaces dpnInterfaces) {
2199 elanInstancToDpnsCache.computeIfAbsent(elanName, key -> new HashSet<>()).remove(dpnInterfaces);
2202 public Optional<IpAddress> getSourceIpAddress(Ethernet ethernet) {
2203 Optional<IpAddress> srcIpAddress = Optional.absent();
2204 if (ethernet.getPayload() == null) {
2205 return srcIpAddress;
2207 byte[] ipAddrBytes = null;
2208 if (ethernet.getPayload() instanceof IPv4) {
2209 IPv4 ipv4 = (IPv4) ethernet.getPayload();
2210 ipAddrBytes = Ints.toByteArray(ipv4.getSourceAddress());
2211 } else if (ethernet.getPayload() instanceof ARP) {
2212 ipAddrBytes = ((ARP) ethernet.getPayload()).getSenderProtocolAddress();
2214 if (ipAddrBytes != null) {
2215 String ipAddr = NWUtil.toStringIpAddress(ipAddrBytes);
2216 return Optional.of(IpAddressBuilder.getDefaultInstance(ipAddr));
2218 return srcIpAddress;
2221 public List<MacEntry> getElanMacEntries(String elanName) {
2222 MacTable macTable = getElanMacTable(elanName);
2223 if (macTable == null) {
2224 return Collections.emptyList();
2226 return macTable.getMacEntry();
2229 public boolean isTunnelInLogicalGroup(String interfaceName, DataBroker broker) {
2230 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
2231 .ietf.interfaces.rev140508.interfaces.Interface configIface =
2232 interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
2233 IfTunnel ifTunnel = configIface.getAugmentation(IfTunnel.class);
2234 if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
2235 ParentRefs refs = configIface.getAugmentation(ParentRefs.class);
2236 if (refs != null && !Strings.isNullOrEmpty(refs.getParentInterface())) {
2237 return true; //multiple VxLAN tunnels enabled, i.e. only logical tunnel should be treated
2243 public static void addElanInterfaceToElanInstanceCache(String elanInstanceName, String elanInterfaceName) {
2244 elanInstanceToInterfacesCache.computeIfAbsent(elanInstanceName, key -> new HashSet<>()).add(elanInterfaceName);
2247 public static void removeElanInterfaceToElanInstanceCache(String elanInstanceName, String interfaceName) {
2248 Set<String> elanInterfaces = elanInstanceToInterfacesCache.get(elanInstanceName);
2249 if (elanInterfaces == null || elanInterfaces.isEmpty()) {
2252 elanInterfaces.remove(interfaceName);
2255 @Nonnull public static Set<String> removeAndGetElanInterfaces(String elanInstanceName) {
2256 Set<String> removed = elanInstanceToInterfacesCache.remove(elanInstanceName);
2257 return removed != null ? removed : Collections.emptySet();
2260 public void addArpResponderFlow(BigInteger dpnId, String ingressInterfaceName, String ipAddress, String macAddress,
2261 int lportTag, List<Instruction> instructions) {
2262 LOG.trace("Installing the ARP responder flow on DPN {} for Interface {} with MAC {} & IP {}", dpnId,
2263 ingressInterfaceName, macAddress, ipAddress);
2265 ElanInterface elanIface = getElanInterfaceByElanInterfaceName(broker, ingressInterfaceName);
2266 ElanInstance elanInstance = getElanInstanceByName(broker, elanIface.getElanInstanceName());
2267 String flowId = ArpResponderUtil.getFlowId(lportTag, ipAddress);
2268 ArpResponderUtil.installFlow(mdsalManager, dpnId, flowId, flowId, NwConstants.DEFAULT_ARP_FLOW_PRIORITY,
2269 ArpResponderUtil.generateCookie(lportTag, ipAddress),
2270 ArpResponderUtil.getMatchCriteria(lportTag, elanInstance, ipAddress), instructions);
2271 LOG.trace("Installed the ARP Responder flow for Interface {}", ingressInterfaceName);
2275 public void removeArpResponderFlow(BigInteger dpnId, String ingressInterfaceName, String ipAddress,
2277 LOG.trace("Removing the ARP responder flow on DPN {} of Interface {} with IP {}", dpnId, ingressInterfaceName,
2279 ArpResponderUtil.removeFlow(mdsalManager, dpnId, ArpResponderUtil.getFlowId(lportTag, ipAddress));
2282 private void buildEtreeDmacFlowForExternalRemoteMacWithBatch(
2283 BigInteger dpnId, String extDeviceNodeId, Long vni, String macAddress, String displayName,
2284 String interfaceName, EtreeLeafTagName etreeLeafTag)throws ElanException {
2286 boolean isRoot = false;
2287 if (interfaceName == null) {
2290 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
2291 if (etreeInterface != null) {
2292 if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
2298 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId,
2299 etreeLeafTag.getEtreeLeafTag().getValue(), vni, macAddress, displayName);
2300 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
2304 private void buildEtreeDmacFlowDropIfPacketComingFromTunnelwithBatch(
2305 BigInteger dpnId, String extDeviceNodeId, Long elanTag, String macAddress,EtreeLeafTagName etreeLeafTag) {
2306 if (etreeLeafTag != null) {
2307 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId,
2308 etreeLeafTag.getEtreeLeafTag().getValue(), macAddress);
2309 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY,
2310 getFlowIid(dropFlow, dpnId),dropFlow);
2314 public void installDmacFlowsToExternalRemoteMacInBatch(
2315 BigInteger dpnId, String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
2316 String interfaceName) throws ElanException {
2318 synchronized (getElanMacDPNKey(elanTag, macAddress, dpnId)) {
2319 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
2321 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
2322 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress);
2323 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY,
2324 getFlowIid(dropFlow, dpnId), dropFlow);
2325 installEtreeDmacFlowsToExternalRemoteMacInBatch(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
2326 displayName, interfaceName);
2330 private void installEtreeDmacFlowsToExternalRemoteMacInBatch(
2331 BigInteger dpnId, String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
2332 String interfaceName) throws ElanException {
2334 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
2335 if (etreeLeafTag != null) {
2336 buildEtreeDmacFlowDropIfPacketComingFromTunnelwithBatch(dpnId, extDeviceNodeId, elanTag, macAddress,
2338 buildEtreeDmacFlowForExternalRemoteMacWithBatch(dpnId, extDeviceNodeId, vni, macAddress, displayName,
2339 interfaceName, etreeLeafTag);
2343 private InstanceIdentifier<Flow> getFlowIid(Flow flow, BigInteger dpnId) {
2344 FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
2345 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId =
2346 new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId("openflow:" + dpnId);
2347 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node nodeDpn =
2348 new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();
2349 return InstanceIdentifier.builder(Nodes.class)
2350 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
2351 nodeDpn.getKey()).augmentation(FlowCapableNode.class)
2352 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();