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.info("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),
1239 elanInfo, WriteTransaction.CREATE_MISSING_PARENTS);
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, WriteTransaction.CREATE_MISSING_PARENTS);
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
1252 EtreeLeafTagName etreeLeafTagName = new EtreeLeafTagNameBuilder()
1253 .setEtreeLeafTag(new EtreeLeafTag(etreeLeafTag)).build();
1254 elanTagNameBuilder.addAugmentation(EtreeLeafTagName.class, etreeLeafTagName);
1255 addTheLeafTagAsElanTag(broker, elanInstanceName, etreeLeafTag, tx);
1257 ElanTagName elanTagName = elanTagNameBuilder.build();
1259 // Add the ElanTag to ElanName in the elan-tag-name Operational
1261 tx.put(LogicalDatastoreType.OPERATIONAL,
1262 getElanInfoEntriesOperationalDataPath(elanTag), elanTagName);
1264 // Updates the ElanInstance Config DS by setting the just acquired
1266 ElanInstanceBuilder elanInstanceBuilder = new ElanInstanceBuilder().setElanInstanceName(elanInstanceName)
1267 .setDescription(elanInstanceAdded.getDescription())
1268 .setMacTimeout(elanInstanceAdded.getMacTimeout() == null ? ElanConstants.DEFAULT_MAC_TIME_OUT
1269 : elanInstanceAdded.getMacTimeout())
1270 .setKey(elanInstanceAdded.getKey()).setElanTag(elanTag);
1271 if (isEtreeInstance(elanInstanceAdded)) {
1272 EtreeInstance etreeInstance = new EtreeInstanceBuilder().setEtreeLeafTagVal(new EtreeLeafTag(etreeLeafTag))
1274 elanInstanceBuilder.addAugmentation(EtreeInstance.class, etreeInstance);
1276 ElanInstance elanInstanceWithTag = elanInstanceBuilder.build();
1277 tx.merge(LogicalDatastoreType.CONFIGURATION, ElanHelper.getElanInstanceConfigurationDataPath(elanInstanceName),
1278 elanInstanceWithTag, true);
1281 private static void addTheLeafTagAsElanTag(DataBroker broker, String elanInstanceName, long etreeLeafTag,
1282 WriteTransaction tx) {
1283 ElanTagName etreeTagAsElanTag = new ElanTagNameBuilder().setElanTag(etreeLeafTag)
1284 .setKey(new ElanTagNameKey(etreeLeafTag)).setName(elanInstanceName).build();
1285 tx.put(LogicalDatastoreType.OPERATIONAL,
1286 getElanInfoEntriesOperationalDataPath(etreeLeafTag), etreeTagAsElanTag);
1289 private static boolean isEtreeInstance(ElanInstance elanInstanceAdded) {
1290 return elanInstanceAdded.getAugmentation(EtreeInstance.class) != null;
1293 public boolean isDpnPresent(BigInteger dpnId) {
1294 String dpn = String.format("%s:%s", "openflow", dpnId);
1295 NodeId nodeId = new NodeId(dpn);
1297 InstanceIdentifier<Node> node = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId))
1299 return read(broker, LogicalDatastoreType.CONFIGURATION, node).isPresent();
1302 public static ServicesInfo getServiceInfo(String elanInstanceName, long elanTag, String interfaceName) {
1303 int priority = ElanConstants.ELAN_SERVICE_PRIORITY;
1304 int instructionKey = 0;
1305 List<Instruction> instructions = new ArrayList<>();
1306 instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(ElanHelper.getElanMetadataLabel(elanTag),
1307 MetaDataUtil.METADATA_MASK_SERVICE, ++instructionKey));
1308 instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.ELAN_SMAC_TABLE, ++instructionKey));
1310 short serviceIndex = ServiceIndex.getIndex(NwConstants.ELAN_SERVICE_NAME, NwConstants.ELAN_SERVICE_INDEX);
1311 ServicesInfo serviceInfo = InterfaceServiceUtil.buildServiceInfo(
1312 String.format("%s.%s", elanInstanceName, interfaceName), serviceIndex, priority,
1313 NwConstants.COOKIE_ELAN_INGRESS_TABLE, instructions);
1317 public static BoundServices getBoundServices(String serviceName, short servicePriority, int flowPriority,
1318 BigInteger cookie, List<Instruction> instructions) {
1319 StypeOpenflowBuilder augBuilder = new StypeOpenflowBuilder().setFlowCookie(cookie).setFlowPriority(flowPriority)
1320 .setInstruction(instructions);
1321 return new BoundServicesBuilder().setKey(new BoundServicesKey(servicePriority)).setServiceName(serviceName)
1322 .setServicePriority(servicePriority).setServiceType(ServiceTypeFlowBased.class)
1323 .addAugmentation(StypeOpenflow.class, augBuilder.build()).build();
1326 public static InstanceIdentifier<BoundServices> buildServiceId(String interfaceName, short serviceIndex) {
1327 return InstanceIdentifier.builder(ServiceBindings.class)
1328 .child(ServicesInfo.class, new ServicesInfoKey(interfaceName, ServiceModeIngress.class))
1329 .child(BoundServices.class, new BoundServicesKey(serviceIndex)).build();
1333 * Builds the list of actions to be taken when sending the packet over a VxLan Tunnel Interface, such as setting
1334 * the network VNI in the tunnel_id field.
1336 * @param tunnelIfaceName
1337 * the tunnel iface name
1342 public List<Action> buildTunnelItmEgressActions(String tunnelIfaceName, Long tunnelKey) {
1343 if (tunnelIfaceName != null && !tunnelIfaceName.isEmpty()) {
1344 return buildItmEgressActions(tunnelIfaceName, tunnelKey);
1347 return Collections.emptyList();
1351 * Builds the list of actions to be taken when sending the packet over external port such as tunnel, physical
1354 * @param interfaceName
1355 * the interface name
1357 * can be VNI for VxLAN tunnel interfaces, Gre Key for GRE
1361 @SuppressWarnings("checkstyle:IllegalCatch")
1362 public List<Action> buildItmEgressActions(String interfaceName, Long tunnelKey) {
1363 List<Action> result = Collections.emptyList();
1365 GetEgressActionsForInterfaceInput getEgressActInput = new GetEgressActionsForInterfaceInputBuilder()
1366 .setIntfName(interfaceName).setTunnelKey(tunnelKey).build();
1368 Future<RpcResult<GetEgressActionsForInterfaceOutput>> egressActionsOutputFuture = interfaceManagerRpcService
1369 .getEgressActionsForInterface(getEgressActInput);
1370 if (egressActionsOutputFuture.get().isSuccessful()) {
1371 GetEgressActionsForInterfaceOutput egressActionsOutput = egressActionsOutputFuture.get().getResult();
1372 result = egressActionsOutput.getAction();
1374 } catch (Exception e) {
1375 LOG.error("Error in RPC call getEgressActionsForInterface {}", e);
1378 if (result == null || result.isEmpty()) {
1379 LOG.warn("Could not build Egress actions for interface {} and tunnelId {}", interfaceName, tunnelKey);
1385 * Builds the list of actions to be taken when sending the packet over an
1386 * external VxLan tunnel interface, such as stamping the VNI on the VxLAN
1387 * header, setting the vlanId if it proceeds and output the packet over the
1391 * Dpn where the tunnelInterface is located
1393 * NodeId of the ExternalDevice where the packet must be sent to.
1395 * Vni to be stamped on the VxLAN Header.
1396 * @return the external itm egress action
1398 public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, NodeId torNode, long vni) {
1399 List<Action> result = Collections.emptyList();
1401 GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
1402 .setDestinationNode(torNode.getValue()).setSourceNode(srcDpnId.toString())
1403 .setTunnelType(TunnelTypeVxlan.class).build();
1404 Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService
1405 .getExternalTunnelInterfaceName(input);
1407 if (output.get().isSuccessful()) {
1408 GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
1409 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
1410 LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
1412 result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
1415 } catch (InterruptedException | ExecutionException e) {
1416 LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
1422 public List<Action> getExternalTunnelItmEgressAction(BigInteger srcDpnId, String nexthopIP, long vni) {
1423 List<Action> result = Collections.emptyList();
1425 GetExternalTunnelInterfaceNameInput input = new GetExternalTunnelInterfaceNameInputBuilder()
1426 .setDestinationNode(nexthopIP).setSourceNode(srcDpnId.toString())
1427 .setTunnelType(TunnelTypeVxlan.class).build();
1428 Future<RpcResult<GetExternalTunnelInterfaceNameOutput>> output = itmRpcService
1429 .getExternalTunnelInterfaceName(input);
1431 if (output.get().isSuccessful()) {
1432 GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
1433 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
1434 LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
1436 result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
1439 } catch (InterruptedException | ExecutionException e) {
1440 LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
1447 * Builds the list of actions to be taken when sending the packet over an internal VxLAN tunnel interface, such
1448 * as setting the serviceTag/segmentationID on the VNI field of the VxLAN header, setting the vlanId if it proceeds
1449 * and output the packet over the right port.
1451 * @param sourceDpnId
1452 * Dpn where the tunnelInterface is located
1453 * @param destinationDpnId
1454 * Dpn where the packet must be sent to. It is used here in order
1455 * to select the right tunnel interface.
1457 * Tunnel key to be sent on the VxLAN header.
1458 * @return the internal itm egress action
1460 public List<Action> getInternalTunnelItmEgressAction(BigInteger sourceDpnId, BigInteger destinationDpnId, long
1462 List<Action> result = Collections.emptyList();
1463 LOG.trace("In getInternalItmEgressAction Action source {}, destination {}, serviceTag/Vni {}", sourceDpnId,
1464 destinationDpnId, tunnelKey);
1465 Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
1466 GetTunnelInterfaceNameInput input = new GetTunnelInterfaceNameInputBuilder()
1467 .setDestinationDpid(destinationDpnId).setSourceDpid(sourceDpnId).setTunnelType(tunType).build();
1468 Future<RpcResult<GetTunnelInterfaceNameOutput>> output = itmRpcService.getTunnelInterfaceName(input);
1470 if (output.get().isSuccessful()) {
1471 GetTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
1472 String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
1473 LOG.info("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
1474 result = buildTunnelItmEgressActions(tunnelIfaceName, tunnelKey);
1476 LOG.trace("Tunnel interface doesn't exist between srcDpId {} dstDpId {}", sourceDpnId,
1479 } catch (InterruptedException | ExecutionException e) {
1480 LOG.error("Error in RPC call getTunnelInterfaceName {}", e);
1486 * Build the list of actions to be taken when sending the packet to external
1489 * @param interfaceName
1491 * @return the external port itm egress actions
1493 public List<Action> getExternalPortItmEgressAction(String interfaceName) {
1494 return buildItmEgressActions(interfaceName, null);
1497 public static List<MatchInfo> getTunnelMatchesForServiceId(int elanTag) {
1498 List<MatchInfo> mkMatches = new ArrayList<>();
1499 // Matching metadata
1500 mkMatches.add(new MatchTunnelId(BigInteger.valueOf(elanTag)));
1505 public void removeTerminatingServiceAction(BigInteger destDpId, int serviceId) {
1506 RemoveTerminatingServiceActionsInput input = new RemoveTerminatingServiceActionsInputBuilder()
1507 .setDpnId(destDpId).setServiceId(serviceId).build();
1508 Future<RpcResult<Void>> futureObject = itmRpcService.removeTerminatingServiceActions(input);
1510 RpcResult<Void> result = futureObject.get();
1511 if (result.isSuccessful()) {
1512 LOG.debug("Successfully completed removeTerminatingServiceActions for ELAN with serviceId {} on "
1513 + "dpn {}", serviceId, destDpId);
1515 LOG.debug("Failure in removeTerminatingServiceAction RPC call for ELAN with serviceId {} on "
1516 + "dpn {}", serviceId, destDpId);
1518 } catch (InterruptedException | ExecutionException e) {
1519 LOG.error("Error in RPC call removeTerminatingServiceActions for ELAN with serviceId {} on "
1520 + "dpn {}: {}", serviceId, destDpId, e);
1525 * Gets the external tunnel.
1527 * @param sourceDevice
1529 * @param destinationDevice
1530 * the destination device
1531 * @param datastoreType
1532 * the datastore type
1533 * @return the external tunnel
1535 public ExternalTunnel getExternalTunnel(String sourceDevice, String destinationDevice,
1536 LogicalDatastoreType datastoreType) {
1537 Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
1538 InstanceIdentifier<ExternalTunnel> iid = InstanceIdentifier.builder(ExternalTunnelList.class)
1539 .child(ExternalTunnel.class, new ExternalTunnelKey(destinationDevice, sourceDevice, tunType)).build();
1540 return read(broker, datastoreType, iid).orNull();
1544 * Gets the external tunnel.
1546 * @param interfaceName
1547 * the interface name
1548 * @param datastoreType
1549 * the datastore type
1550 * @return the external tunnel
1552 public ExternalTunnel getExternalTunnel(String interfaceName, LogicalDatastoreType datastoreType) {
1553 ExternalTunnel externalTunnel = null;
1554 List<ExternalTunnel> externalTunnels = getAllExternalTunnels(datastoreType);
1555 for (ExternalTunnel tunnel : externalTunnels) {
1556 if (StringUtils.equalsIgnoreCase(interfaceName, tunnel.getTunnelInterfaceName())) {
1557 externalTunnel = tunnel;
1561 return externalTunnel;
1565 * Gets the all external tunnels.
1567 * @param datastoreType
1568 * the data store type
1569 * @return the all external tunnels
1571 public List<ExternalTunnel> getAllExternalTunnels(LogicalDatastoreType datastoreType) {
1572 InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
1573 return read(broker, datastoreType, iid).toJavaUtil().map(ExternalTunnelList::getExternalTunnel).orElse(
1574 Collections.emptyList());
1578 * Installs a Flow in the specified DPN's DMAC table. The flow is for a MAC
1579 * that is connected remotely in an External Device (TOR) and that is
1580 * accessible through an external tunnel. It also installs the flow for
1581 * dropping the packet if it came over an ITM tunnel (that is, if the
1582 * Split-Horizon flag is set)
1585 * Id of the DPN where the flow must be installed
1586 * @param extDeviceNodeId
1587 * the ext device node id
1594 * @param displayName
1596 * @param interfaceName
1597 * the interface name
1599 * @return the dmac flows
1600 * @throws ElanException in case of issues creating the flow objects
1602 public List<ListenableFuture<Void>> installDmacFlowsToExternalRemoteMac(BigInteger dpnId,
1603 String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
1604 String interfaceName) throws ElanException {
1605 List<ListenableFuture<Void>> futures = new ArrayList<>();
1606 synchronized (getElanMacDPNKey(elanTag, macAddress, dpnId)) {
1607 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
1609 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
1611 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress);
1612 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(dropFlow, dpnId),
1614 installEtreeDmacFlowsToExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress, displayName,
1615 interfaceName, futures);
1620 private void installEtreeDmacFlowsToExternalRemoteMac(BigInteger dpnId, String extDeviceNodeId, Long elanTag,
1621 Long vni, String macAddress, String displayName, String interfaceName,
1622 List<ListenableFuture<Void>> futures) throws ElanException {
1623 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
1624 if (etreeLeafTag != null) {
1625 buildEtreeDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress, futures,
1627 buildEtreeDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, vni, macAddress, displayName, interfaceName,
1628 futures, etreeLeafTag);
1632 private void buildEtreeDmacFlowForExternalRemoteMac(BigInteger dpnId, String extDeviceNodeId, Long vni,
1633 String macAddress, String displayName, String interfaceName, List<ListenableFuture<Void>> futures,
1634 EtreeLeafTagName etreeLeafTag) throws ElanException {
1635 boolean isRoot = false;
1636 if (interfaceName == null) {
1639 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
1640 if (etreeInterface != null) {
1641 if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
1647 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId,
1648 etreeLeafTag.getEtreeLeafTag().getValue(), vni, macAddress, displayName);
1649 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
1653 private void buildEtreeDmacFlowDropIfPacketComingFromTunnel(BigInteger dpnId, String extDeviceNodeId,
1654 Long elanTag, String macAddress, List<ListenableFuture<Void>> futures, EtreeLeafTagName etreeLeafTag) {
1655 if (etreeLeafTag != null) {
1656 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId,
1657 etreeLeafTag.getEtreeLeafTag().getValue(), macAddress);
1658 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(dropFlow, dpnId),
1663 public static List<MatchInfo> buildMatchesForElanTagShFlagAndDstMac(long elanTag, boolean shFlag, String macAddr) {
1664 List<MatchInfo> mkMatches = new ArrayList<>();
1666 new MatchMetadata(getElanMetadataLabel(elanTag, shFlag), MetaDataUtil.METADATA_MASK_SERVICE_SH_FLAG));
1667 mkMatches.add(new MatchEthernetDestination(new MacAddress(macAddr)));
1672 * Builds a Flow to be programmed in a DPN's DMAC table. This method must be
1673 * used when the MAC is located in an External Device (TOR). The flow
1674 * matches on the specified MAC and 1) sends the packet over the CSS-TOR
1675 * tunnel if SHFlag is not set, or 2) drops it if SHFlag is set (what means
1676 * the packet came from an external tunnel)
1679 * DPN whose DMAC table is going to be modified
1680 * @param extDeviceNodeId
1681 * Hwvtep node where the mac is attached to
1683 * ElanId to which the MAC is being added to
1686 * @param dstMacAddress
1687 * The mac address to be programmed
1688 * @param displayName
1691 * @throws ElanException in case of issues creating the flow objects
1693 @SuppressWarnings("checkstyle:IllegalCatch")
1694 public Flow buildDmacFlowForExternalRemoteMac(BigInteger dpId, String extDeviceNodeId, long elanTag,
1695 Long vni, String dstMacAddress, String displayName) throws ElanException {
1696 List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */ false, dstMacAddress);
1697 List<Instruction> mkInstructions = new ArrayList<>();
1699 List<Action> actions = getExternalTunnelItmEgressAction(dpId, new NodeId(extDeviceNodeId), vni);
1700 mkInstructions.add(MDSALUtil.buildApplyActionsInstruction(actions));
1701 } catch (Exception e) {
1702 LOG.error("Could not get Egress Actions for DpId=" + dpId + ", externalNode=" + extDeviceNodeId, e);
1705 Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE,
1706 getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, dstMacAddress, elanTag,
1709 displayName, 0, /* idleTimeout */
1710 0, /* hardTimeout */
1711 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
1717 * Builds the flow that drops the packet if it came through an external
1718 * tunnel, that is, if the Split-Horizon flag is set.
1721 * DPN whose DMAC table is going to be modified
1722 * @param extDeviceNodeId
1723 * Hwvtep node where the mac is attached to
1725 * ElanId to which the MAC is being added to
1726 * @param dstMacAddress
1727 * The mac address to be programmed
1729 private static Flow buildDmacFlowDropIfPacketComingFromTunnel(BigInteger dpnId, String extDeviceNodeId,
1730 Long elanTag, String dstMacAddress) {
1731 List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, SH_FLAG_SET, dstMacAddress);
1732 List<Instruction> mkInstructions = MDSALUtil.buildInstructionsDrop();
1733 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpnId, extDeviceNodeId, dstMacAddress,
1735 Flow flow = MDSALUtil.buildFlowNew(NwConstants.ELAN_DMAC_TABLE, flowId, 20, /* prio */
1736 "Drop", 0, /* idleTimeout */
1737 0, /* hardTimeout */
1738 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)), mkMatches, mkInstructions);
1743 private static String getDmacDropFlowId(Long elanTag, String dstMacAddress) {
1744 return new StringBuilder(NwConstants.ELAN_DMAC_TABLE).append(elanTag).append(dstMacAddress).append("Drop")
1749 * Installs or removes flows in DMAC table for MACs that are/were located in
1750 * an external Elan Device.
1753 * Id of the DPN where the DMAC table is going to be modified
1755 * Id of the External Device where the MAC is located
1759 * VNI of the LogicalSwitch to which the MAC belongs to, and that
1760 * is associated with the ELAN
1763 * @param elanInstanceName
1764 * the elan instance name
1765 * @param addOrRemove
1766 * Indicates if flows must be installed or removed.
1767 * @param interfaceName
1768 * the interface name
1769 * @throws ElanException in case of issues creating the flow objects
1770 * @see org.opendaylight.genius.mdsalutil.MDSALUtil.MdsalOp
1772 public void setupDmacFlowsToExternalRemoteMac(BigInteger dpId, String extNodeId, Long elanTag, Long vni,
1773 String macAddress, String elanInstanceName, MdsalOp addOrRemove, String interfaceName)
1774 throws ElanException {
1775 if (addOrRemove == MdsalOp.CREATION_OP) {
1776 installDmacFlowsToExternalRemoteMac(dpId, extNodeId, elanTag, vni, macAddress, elanInstanceName,
1778 } else if (addOrRemove == MdsalOp.REMOVAL_OP) {
1779 deleteDmacFlowsToExternalMac(elanTag, dpId, extNodeId, macAddress);
1784 * Delete dmac flows to external mac.
1790 * @param extDeviceNodeId
1791 * the ext device node id
1792 * @param macToRemove
1796 public List<ListenableFuture<Void>> deleteDmacFlowsToExternalMac(long elanTag, BigInteger dpId,
1797 String extDeviceNodeId, String macToRemove) {
1798 List<ListenableFuture<Void>> futures = new ArrayList<>();
1799 synchronized (getElanMacDPNKey(elanTag, macToRemove, dpId)) {
1800 // Removing the flows that sends the packet on an external tunnel
1801 removeFlowThatSendsThePacketOnAnExternalTunnel(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
1803 // And now removing the drop flow
1804 removeTheDropFlow(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
1806 deleteEtreeDmacFlowsToExternalMac(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
1811 private void deleteEtreeDmacFlowsToExternalMac(long elanTag, BigInteger dpId, String extDeviceNodeId,
1812 String macToRemove, List<ListenableFuture<Void>> futures) {
1813 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
1814 if (etreeLeafTag != null) {
1815 removeFlowThatSendsThePacketOnAnExternalTunnel(etreeLeafTag.getEtreeLeafTag().getValue(), dpId,
1816 extDeviceNodeId, macToRemove, futures);
1817 removeTheDropFlow(etreeLeafTag.getEtreeLeafTag().getValue(), dpId, extDeviceNodeId, macToRemove, futures);
1821 private void removeTheDropFlow(long elanTag, BigInteger dpId, String extDeviceNodeId, String macToRemove,
1822 List<ListenableFuture<Void>> futures) {
1823 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, macToRemove,
1825 Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
1826 ResourceBatchingManager.getInstance().delete(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flowToRemove, dpId));
1829 private void removeFlowThatSendsThePacketOnAnExternalTunnel(long elanTag, BigInteger dpId,
1830 String extDeviceNodeId, String macToRemove, List<ListenableFuture<Void>> futures) {
1831 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, extDeviceNodeId, macToRemove,
1833 Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
1834 ResourceBatchingManager.getInstance().delete(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flowToRemove, dpId));
1838 * Gets the dpid from interface.
1840 * @param interfaceName
1841 * the interface name
1842 * @return the dpid from interface
1844 public BigInteger getDpidFromInterface(String interfaceName) {
1845 BigInteger dpId = null;
1846 Future<RpcResult<GetDpidFromInterfaceOutput>> output = interfaceManagerRpcService
1847 .getDpidFromInterface(new GetDpidFromInterfaceInputBuilder().setIntfName(interfaceName).build());
1849 RpcResult<GetDpidFromInterfaceOutput> rpcResult = output.get();
1850 if (rpcResult.isSuccessful()) {
1851 dpId = rpcResult.getResult().getDpid();
1853 } catch (NullPointerException | InterruptedException | ExecutionException e) {
1854 LOG.error("Failed to get the DPN ID: {} for interface {}: {} ", dpId, interfaceName, e);
1860 * Checks if is interface operational.
1862 * @param interfaceName
1863 * the interface name
1866 * @return true, if is interface operational
1868 public static boolean isInterfaceOperational(String interfaceName, DataBroker dataBroker) {
1869 if (StringUtils.isBlank(interfaceName)) {
1872 Interface ifState = getInterfaceStateFromOperDS(interfaceName, dataBroker);
1873 if (ifState == null) {
1876 return ifState.getOperStatus() == OperStatus.Up && ifState.getAdminStatus() == AdminStatus.Up;
1880 * Gets the interface state from operational ds.
1882 * @param interfaceName
1883 * the interface name
1886 * @return the interface state from oper ds
1888 public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1889 .ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS(
1890 String interfaceName, DataBroker dataBroker) {
1891 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1892 .ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = createInterfaceStateInstanceIdentifier(
1894 return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId).orNull();
1898 * Creates the interface state instance identifier.
1900 * @param interfaceName
1901 * the interface name
1902 * @return the instance identifier
1904 public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1905 .ietf.interfaces.rev140508.interfaces.state.Interface> createInterfaceStateInstanceIdentifier(
1906 String interfaceName) {
1907 InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1908 .ietf.interfaces.rev140508.interfaces.state.Interface> idBuilder = InstanceIdentifier
1909 .builder(InterfacesState.class)
1910 .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1911 .ietf.interfaces.rev140508.interfaces.state.Interface.class,
1912 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
1913 .ietf.interfaces.rev140508.interfaces.state.InterfaceKey(
1915 return idBuilder.build();
1918 public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
1919 WriteTransaction tx) {
1920 CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
1923 } catch (InterruptedException | ExecutionException e) {
1924 LOG.error("Error writing to datastore {}", e);
1929 public static boolean isVxlanNetwork(DataBroker broker, String elanInstanceName) {
1930 ElanInstance elanInstance = getElanInstanceByName(broker, elanInstanceName);
1931 return elanInstance != null && isVxlan(elanInstance);
1934 public static boolean isVxlan(ElanInstance elanInstance) {
1935 return elanInstance != null && elanInstance.getSegmentType() != null
1936 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1937 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
1940 private static boolean isVxlanSegment(ElanInstance elanInstance) {
1941 if (elanInstance != null) {
1942 List<ElanSegments> elanSegments = elanInstance.getElanSegments();
1943 if (elanSegments != null) {
1944 for (ElanSegments segment : elanSegments) {
1945 if (segment != null && segment.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1946 && segment.getSegmentationId() != null
1947 && segment.getSegmentationId().longValue() != 0) {
1956 public static boolean isVxlanNetworkOrVxlanSegment(ElanInstance elanInstance) {
1957 return isVxlan(elanInstance) || isVxlanSegment(elanInstance);
1960 public static Long getVxlanSegmentationId(ElanInstance elanInstance) {
1961 Long segmentationId = 0L;
1963 if (elanInstance != null && elanInstance.getSegmentType() != null
1964 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1965 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId().longValue() != 0) {
1966 segmentationId = elanInstance.getSegmentationId();
1968 for (ElanSegments segment: elanInstance.getElanSegments()) {
1969 if (segment != null && segment.getSegmentType().isAssignableFrom(SegmentTypeVxlan.class)
1970 && segment.getSegmentationId() != null
1971 && segment.getSegmentationId().longValue() != 0) {
1972 segmentationId = segment.getSegmentationId();
1976 return segmentationId;
1979 public static boolean isVlan(ElanInstance elanInstance) {
1980 return elanInstance != null && elanInstance.getSegmentType() != null
1981 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeVlan.class)
1982 && elanInstance.getSegmentationId() != null && elanInstance.getSegmentationId() != 0;
1985 public static boolean isFlat(ElanInstance elanInstance) {
1986 return elanInstance != null && elanInstance.getSegmentType() != null
1987 && elanInstance.getSegmentType().isAssignableFrom(SegmentTypeFlat.class);
1990 public void handleDmacRedirectToDispatcherFlows(Long elanTag, String displayName,
1991 String macAddress, int addOrRemove, List<BigInteger> dpnIds) {
1992 for (BigInteger dpId : dpnIds) {
1993 if (addOrRemove == NwConstants.ADD_FLOW) {
1994 WriteTransaction writeTx = broker.newWriteOnlyTransaction();
1995 mdsalManager.addFlowToTx(buildDmacRedirectToDispatcherFlow(dpId, macAddress, displayName, elanTag),
1999 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, macAddress, elanTag);
2000 mdsalManager.removeFlow(dpId, MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, flowId));
2005 public static FlowEntity buildDmacRedirectToDispatcherFlow(BigInteger dpId, String dstMacAddress,
2006 String displayName, long elanTag) {
2007 List<MatchInfo> matches = new ArrayList<>();
2008 matches.add(new MatchMetadata(ElanHelper.getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE));
2009 matches.add(new MatchEthernetDestination(new MacAddress(dstMacAddress)));
2010 List<InstructionInfo> instructions = new ArrayList<>();
2011 List<ActionInfo> actions = new ArrayList<>();
2012 actions.add(new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
2014 instructions.add(new InstructionApplyActions(actions));
2015 String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, dstMacAddress, elanTag);
2016 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 20, displayName, 0, 0,
2017 ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)),
2018 matches, instructions);
2023 * Add Mac Address to ElanInterfaceForwardingEntries and ElanForwardingTables
2024 * Install SMAC and DMAC flows.
2026 public void addMacEntryToDsAndSetupFlows(IInterfaceManager interfaceManager, String interfaceName,
2027 String macAddress, String elanName, WriteTransaction tx, WriteTransaction flowWritetx, int macTimeOut)
2028 throws ElanException {
2029 LOG.trace("Adding mac address {} and interface name {} to ElanInterfaceForwardingEntries and "
2030 + "ElanForwardingTables DS", macAddress, interfaceName);
2031 BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
2032 PhysAddress physAddress = new PhysAddress(macAddress);
2033 MacEntry macEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress)
2034 .setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp)
2035 .setIsStaticAddress(false).build();
2036 InstanceIdentifier<MacEntry> macEntryId = ElanUtils
2037 .getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
2038 tx.put(LogicalDatastoreType.OPERATIONAL, macEntryId, macEntry);
2039 InstanceIdentifier<MacEntry> elanMacEntryId = ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
2040 tx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
2041 ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
2042 setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress, true,
2047 * Remove Mac Address from ElanInterfaceForwardingEntries and ElanForwardingTables
2048 * Remove SMAC and DMAC flows.
2050 public void deleteMacEntryFromDsAndRemoveFlows(IInterfaceManager interfaceManager, String interfaceName,
2051 String macAddress, String elanName, WriteTransaction tx, WriteTransaction deleteFlowTx) {
2052 LOG.trace("Deleting mac address {} and interface name {} from ElanInterfaceForwardingEntries "
2053 + "and ElanForwardingTables DS", macAddress, interfaceName);
2054 PhysAddress physAddress = new PhysAddress(macAddress);
2055 MacEntry macEntry = getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
2056 InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
2057 if (macEntry != null && interfaceInfo != null) {
2058 deleteMacFlows(ElanUtils.getElanInstanceByName(broker, elanName), interfaceInfo, macEntry, deleteFlowTx);
2060 tx.delete(LogicalDatastoreType.OPERATIONAL,
2061 ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress));
2062 tx.delete(LogicalDatastoreType.OPERATIONAL,
2063 ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress));
2066 public String getExternalElanInterface(String elanInstanceName, BigInteger dpnId) {
2067 DpnInterfaces dpnInterfaces = getElanInterfaceInfoByElanDpn(elanInstanceName, dpnId);
2068 if (dpnInterfaces == null || dpnInterfaces.getInterfaces() == null) {
2069 LOG.trace("Elan {} does not have interfaces in DPN {}", elanInstanceName, dpnId);
2073 for (String dpnInterface : dpnInterfaces.getInterfaces()) {
2074 if (interfaceManager.isExternalInterface(dpnInterface)) {
2075 return dpnInterface;
2079 LOG.trace("Elan {} does not have any external interace attached to DPN {}", elanInstanceName, dpnId);
2083 public static String getElanMacDPNKey(long elanTag, String macAddress, BigInteger dpnId) {
2084 String elanMacDmacDpnKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag + "DPN_ID-" + dpnId;
2085 return elanMacDmacDpnKey.intern();
2088 public static String getElanMacKey(long elanTag, String macAddress) {
2089 String elanMacKey = "MAC-" + macAddress + " ELAN_TAG-" + elanTag;
2090 return elanMacKey.intern();
2094 public static void addToListenableFutureIfTxException(RuntimeException exception,
2095 List<ListenableFuture<Void>> futures) {
2096 Throwable cause = exception.getCause();
2097 if (cause != null && cause instanceof TransactionCommitFailedException) {
2098 futures.add(Futures.immediateFailedCheckedFuture((TransactionCommitFailedException) cause));
2102 public static List<PhysAddress> getPhysAddress(List<String> macAddress) {
2103 Preconditions.checkNotNull(macAddress, "macAddress cannot be null");
2104 List<PhysAddress> physAddresses = new ArrayList<>();
2105 for (String mac : macAddress) {
2106 physAddresses.add(new PhysAddress(mac));
2108 return physAddresses;
2111 public static List<StaticMacEntries> getStaticMacEntries(List<String> staticMacAddresses) {
2112 if (isEmpty(staticMacAddresses)) {
2113 return Collections.EMPTY_LIST;
2115 StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
2116 List<StaticMacEntries> staticMacEntries = new ArrayList<>();
2117 List<PhysAddress> physAddressList = getPhysAddress(staticMacAddresses);
2118 for (PhysAddress physAddress : physAddressList) {
2119 staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
2121 return staticMacEntries;
2124 public static InstanceIdentifier<StaticMacEntries> getStaticMacEntriesCfgDataPathIdentifier(String interfaceName,
2125 String macAddress) {
2126 return InstanceIdentifier.builder(ElanInterfaces.class)
2127 .child(ElanInterface.class, new ElanInterfaceKey(interfaceName)).child(StaticMacEntries.class,
2128 new StaticMacEntriesKey(new PhysAddress(macAddress))).build();
2131 public static List<StaticMacEntries> getDeletedEntries(List<StaticMacEntries> originalStaticMacEntries,
2132 List<StaticMacEntries> updatedStaticMacEntries) {
2133 if (isEmpty(originalStaticMacEntries)) {
2134 return Collections.EMPTY_LIST;
2136 List<StaticMacEntries> deleted = Lists.newArrayList(originalStaticMacEntries);
2137 if (isNotEmpty(updatedStaticMacEntries)) {
2138 deleted.removeAll(updatedStaticMacEntries);
2143 public static <T> List<T> diffOf(List<T> orig, List<T> updated) {
2144 if (isEmpty(orig)) {
2145 return Collections.EMPTY_LIST;
2147 List<T> diff = Lists.newArrayList(orig);
2148 if (isNotEmpty(updated)) {
2149 diff.removeAll(updated);
2154 public static void segregateToBeDeletedAndAddEntries(List<StaticMacEntries> originalStaticMacEntries,
2155 List<StaticMacEntries> updatedStaticMacEntries) {
2156 if (isNotEmpty(updatedStaticMacEntries)) {
2157 List<StaticMacEntries> existingClonedStaticMacEntries = new ArrayList<>();
2158 if (isNotEmpty(originalStaticMacEntries)) {
2159 existingClonedStaticMacEntries.addAll(0, originalStaticMacEntries);
2160 originalStaticMacEntries.removeAll(updatedStaticMacEntries);
2161 updatedStaticMacEntries.removeAll(existingClonedStaticMacEntries);
2166 public static boolean isEmpty(Collection collection) {
2167 return collection == null || collection.isEmpty();
2170 public static boolean isNotEmpty(Collection collection) {
2171 return !isEmpty(collection);
2174 public static void setElanInstancToDpnsCache(Map<String, Set<DpnInterfaces>> elanInstancToDpnsCache) {
2175 ElanUtils.elanInstancToDpnsCache = elanInstancToDpnsCache;
2178 public static Set<DpnInterfaces> getElanInvolvedDPNsFromCache(String elanName) {
2179 return elanInstancToDpnsCache.get(elanName);
2182 public static void addDPNInterfaceToElanInCache(String elanName, DpnInterfaces dpnInterfaces) {
2183 elanInstancToDpnsCache.computeIfAbsent(elanName, key -> new HashSet<>()).add(dpnInterfaces);
2186 public static void removeDPNInterfaceFromElanInCache(String elanName, DpnInterfaces dpnInterfaces) {
2187 elanInstancToDpnsCache.computeIfAbsent(elanName, key -> new HashSet<>()).remove(dpnInterfaces);
2190 public Optional<IpAddress> getSourceIpAddress(Ethernet ethernet) {
2191 Optional<IpAddress> srcIpAddress = Optional.absent();
2192 if (ethernet.getPayload() == null) {
2193 return srcIpAddress;
2195 byte[] ipAddrBytes = null;
2196 if (ethernet.getPayload() instanceof IPv4) {
2197 IPv4 ipv4 = (IPv4) ethernet.getPayload();
2198 ipAddrBytes = Ints.toByteArray(ipv4.getSourceAddress());
2199 } else if (ethernet.getPayload() instanceof ARP) {
2200 ipAddrBytes = ((ARP) ethernet.getPayload()).getSenderProtocolAddress();
2202 if (ipAddrBytes != null) {
2203 String ipAddr = NWUtil.toStringIpAddress(ipAddrBytes);
2204 return Optional.of(IpAddressBuilder.getDefaultInstance(ipAddr));
2206 return srcIpAddress;
2209 public List<MacEntry> getElanMacEntries(String elanName) {
2210 MacTable macTable = getElanMacTable(elanName);
2211 if (macTable == null) {
2212 return Collections.emptyList();
2214 return macTable.getMacEntry();
2217 public boolean isTunnelInLogicalGroup(String interfaceName, DataBroker broker) {
2218 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
2219 .ietf.interfaces.rev140508.interfaces.Interface configIface =
2220 interfaceManager.getInterfaceInfoFromConfigDataStore(interfaceName);
2221 IfTunnel ifTunnel = configIface.getAugmentation(IfTunnel.class);
2222 if (ifTunnel != null && ifTunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeVxlan.class)) {
2223 ParentRefs refs = configIface.getAugmentation(ParentRefs.class);
2224 if (refs != null && !Strings.isNullOrEmpty(refs.getParentInterface())) {
2225 return true; //multiple VxLAN tunnels enabled, i.e. only logical tunnel should be treated
2231 public static void addElanInterfaceToElanInstanceCache(String elanInstanceName, String elanInterfaceName) {
2232 elanInstanceToInterfacesCache.computeIfAbsent(elanInstanceName, key -> new HashSet<>()).add(elanInterfaceName);
2235 public static void removeElanInterfaceToElanInstanceCache(String elanInstanceName, String interfaceName) {
2236 Set<String> elanInterfaces = elanInstanceToInterfacesCache.get(elanInstanceName);
2237 if (elanInterfaces == null || elanInterfaces.isEmpty()) {
2240 elanInterfaces.remove(interfaceName);
2243 @Nonnull public static Set<String> removeAndGetElanInterfaces(String elanInstanceName) {
2244 Set<String> removed = elanInstanceToInterfacesCache.remove(elanInstanceName);
2245 return removed != null ? removed : Collections.emptySet();
2248 private void buildEtreeDmacFlowForExternalRemoteMacWithBatch(
2249 BigInteger dpnId, String extDeviceNodeId, Long vni, String macAddress, String displayName,
2250 String interfaceName, EtreeLeafTagName etreeLeafTag)throws ElanException {
2252 boolean isRoot = false;
2253 if (interfaceName == null) {
2256 EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
2257 if (etreeInterface != null) {
2258 if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
2264 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId,
2265 etreeLeafTag.getEtreeLeafTag().getValue(), vni, macAddress, displayName);
2266 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
2270 private void buildEtreeDmacFlowDropIfPacketComingFromTunnelwithBatch(
2271 BigInteger dpnId, String extDeviceNodeId, Long elanTag, String macAddress,EtreeLeafTagName etreeLeafTag) {
2272 if (etreeLeafTag != null) {
2273 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId,
2274 etreeLeafTag.getEtreeLeafTag().getValue(), macAddress);
2275 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY,
2276 getFlowIid(dropFlow, dpnId),dropFlow);
2280 public void installDmacFlowsToExternalRemoteMacInBatch(
2281 BigInteger dpnId, String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
2282 String interfaceName) throws ElanException {
2284 synchronized (getElanMacDPNKey(elanTag, macAddress, dpnId)) {
2285 Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
2287 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY, getFlowIid(flow, dpnId), flow);
2288 Flow dropFlow = buildDmacFlowDropIfPacketComingFromTunnel(dpnId, extDeviceNodeId, elanTag, macAddress);
2289 ResourceBatchingManager.getInstance().put(ShardResource.CONFIG_TOPOLOGY,
2290 getFlowIid(dropFlow, dpnId), dropFlow);
2291 installEtreeDmacFlowsToExternalRemoteMacInBatch(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
2292 displayName, interfaceName);
2296 private void installEtreeDmacFlowsToExternalRemoteMacInBatch(
2297 BigInteger dpnId, String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
2298 String interfaceName) throws ElanException {
2300 EtreeLeafTagName etreeLeafTag = getEtreeLeafTagByElanTag(elanTag);
2301 if (etreeLeafTag != null) {
2302 buildEtreeDmacFlowDropIfPacketComingFromTunnelwithBatch(dpnId, extDeviceNodeId, elanTag, macAddress,
2304 buildEtreeDmacFlowForExternalRemoteMacWithBatch(dpnId, extDeviceNodeId, vni, macAddress, displayName,
2305 interfaceName, etreeLeafTag);
2309 private InstanceIdentifier<Flow> getFlowIid(Flow flow, BigInteger dpnId) {
2310 FlowKey flowKey = new FlowKey(new FlowId(flow.getId()));
2311 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId nodeId =
2312 new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId("openflow:" + dpnId);
2313 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node nodeDpn =
2314 new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();
2315 return InstanceIdentifier.builder(Nodes.class)
2316 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
2317 nodeDpn.getKey()).augmentation(FlowCapableNode.class)
2318 .child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flowKey).build();
2321 public static String getElanInterfaceJobKey(String interfaceName) {
2322 return "elaninterface-" + interfaceName;
2325 public void addArpResponderFlow(BigInteger dpnId, String ingressInterfaceName, String ipAddress, String macAddress,
2326 int lportTag, List<Instruction> instructions) {
2327 LOG.info("Installing the ARP responder flow on DPN {} for Interface {} with MAC {} & IP {}", dpnId,
2328 ingressInterfaceName, macAddress, ipAddress);
2329 ElanInterface elanIface = getElanInterfaceByElanInterfaceName(broker, ingressInterfaceName);
2330 ElanInstance elanInstance = getElanInstanceByName(broker, elanIface.getElanInstanceName());
2331 if (elanInstance == null) {
2332 LOG.debug("addArpResponderFlow: elanInstance is null, Failed to install arp responder flow for Interface {}"
2333 + " with MAC {} & IP {}", dpnId,
2334 ingressInterfaceName, macAddress, ipAddress);
2337 String flowId = ArpResponderUtil.getFlowId(lportTag, ipAddress);
2338 ArpResponderUtil.installFlow(mdsalManager, dpnId, flowId, flowId, NwConstants.DEFAULT_ARP_FLOW_PRIORITY,
2339 ArpResponderUtil.generateCookie(lportTag, ipAddress),
2340 ArpResponderUtil.getMatchCriteria(lportTag, elanInstance, ipAddress), instructions);
2341 LOG.info("Installed the ARP Responder flow for Interface {}", ingressInterfaceName);
2344 public void removeArpResponderFlow(BigInteger dpnId, String ingressInterfaceName, String ipAddress,
2346 LOG.info("Removing the ARP responder flow on DPN {} of Interface {} with IP {}", dpnId, ingressInterfaceName,
2348 ArpResponderUtil.removeFlow(mdsalManager, dpnId, ArpResponderUtil.getFlowId(lportTag, ipAddress));