2 * Copyright (c) 2016 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.fibmanager;
10 import static org.opendaylight.netvirt.fibmanager.FibConstants.COOKIE_TUNNEL;
11 import static org.opendaylight.netvirt.fibmanager.FibConstants.DEFAULT_FIB_FLOW_PRIORITY;
12 import static org.opendaylight.netvirt.fibmanager.FibConstants.FLOWID_PREFIX;
14 import com.google.common.base.Optional;
15 import com.google.common.util.concurrent.Futures;
16 import java.math.BigInteger;
17 import java.net.InetAddress;
18 import java.net.UnknownHostException;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.Future;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.genius.mdsalutil.ActionInfo;
26 import org.opendaylight.genius.mdsalutil.ActionType;
27 import org.opendaylight.genius.mdsalutil.InstructionInfo;
28 import org.opendaylight.genius.mdsalutil.InstructionType;
29 import org.opendaylight.genius.mdsalutil.MDSALUtil;
30 import org.opendaylight.genius.mdsalutil.MatchFieldType;
31 import org.opendaylight.genius.mdsalutil.MatchInfo;
32 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
33 import org.opendaylight.genius.mdsalutil.NwConstants;
34 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
35 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CleanupDpnForVpnInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.PopulateFibOnDpnInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceToVpnId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryKey;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddressesBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddressesKey;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfaces;
54 import org.opendaylight.yangtools.yang.binding.DataObject;
55 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
56 import org.opendaylight.yangtools.yang.common.RpcResult;
57 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
61 public class FibRpcServiceImpl implements FibRpcService {
62 private static final Logger LOG = LoggerFactory.getLogger(FibRpcServiceImpl.class);
63 private final DataBroker dataBroker;
64 private final IMdsalApiManager mdsalManager;
65 private final IFibManager fibManager;
67 public FibRpcServiceImpl(final DataBroker dataBroker, final IMdsalApiManager mdsalManager,
68 final IFibManager fibManager) {
69 this.dataBroker = dataBroker;
70 this.mdsalManager = mdsalManager;
71 this.fibManager = fibManager;
75 * to install FIB routes on specified dpn with given instructions
79 public Future<RpcResult<Void>> createFibEntry(CreateFibEntryInput input) {
81 BigInteger dpnId = input.getSourceDpid();
82 String vpnName = input.getVpnName();
83 long vpnId = getVpnId(dataBroker, vpnName);
84 String vpnRd = getVpnRd(dataBroker, vpnName);
85 String ipAddress = input.getIpAddress();
86 LOG.info("Create custom FIB entry - {} on dpn {} for VPN {} ", ipAddress, dpnId, vpnName);
87 List<Instruction> instructions = input.getInstruction();
88 LOG.info("ADD: Adding Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
89 makeLocalFibEntry(vpnId, dpnId, ipAddress, instructions);
90 updateVpnToDpnAssociation(vpnId, dpnId, ipAddress, vpnName);
91 LOG.info("ADD: Added Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
92 return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
96 * to remove FIB/LFIB/TST routes from specified dpn
100 public Future<RpcResult<Void>> removeFibEntry(RemoveFibEntryInput input) {
101 BigInteger dpnId = input.getSourceDpid();
102 String vpnName = input.getVpnName();
103 long vpnId = getVpnId(dataBroker, vpnName);
104 String vpnRd = getVpnRd(dataBroker, vpnName);
105 long serviceId = input.getServiceId();
106 String ipAddress = input.getIpAddress();
108 LOG.info("Delete custom FIB entry - {} on dpn {} for VPN {} ", ipAddress, dpnId, vpnName);
109 LOG.info("REMOVE: Removing Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
110 removeLocalFibEntry(dpnId, vpnId, ipAddress);
111 //removeLFibTableEntry(dpnId, serviceId);
112 //removeTunnelTableEntry(dpnId, serviceId);
113 removeFromVpnDpnAssociation(vpnId, dpnId, ipAddress, vpnName);
114 LOG.info("REMOVE: Removed Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
116 return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
121 public Future<RpcResult<Void>> populateFibOnDpn(PopulateFibOnDpnInput input) {
122 fibManager.populateFibOnNewDpn(input.getDpid(), input.getVpnId(), input.getRd(), null);
123 return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
127 public Future<RpcResult<Void>> cleanupDpnForVpn(CleanupDpnForVpnInput input) {
128 fibManager.cleanUpDpnForVpn(input.getDpid(), input.getVpnId(), input.getRd(), null);
129 return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
132 private void removeLocalFibEntry(BigInteger dpnId, long vpnId, String ipPrefix) {
133 String values[] = ipPrefix.split("/");
134 String ipAddress = values[0];
135 int prefixLength = (values.length == 1) ? 0 : Integer.parseInt(values[1]);
136 LOG.debug("Removing route from DPN. ip {} masklen {}", ipAddress, prefixLength);
137 InetAddress destPrefix = null;
139 destPrefix = InetAddress.getByName(ipAddress);
140 } catch (UnknownHostException e) {
141 LOG.error("UnknowHostException in removeRoute. Failed to remove Route for ipPrefix {}", ipAddress, e);
144 List<MatchInfo> matches = new ArrayList<MatchInfo>();
146 matches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
147 MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID }));
149 matches.add(new MatchInfo(MatchFieldType.eth_type,
150 new long[] { 0x0800L }));
152 if(prefixLength != 0) {
153 matches.add(new MatchInfo(MatchFieldType.ipv4_destination, new String[] {
154 destPrefix.getHostAddress(), Integer.toString(prefixLength) }));
157 String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
160 int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
161 Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef,
162 priority, flowRef, 0, 0,
163 NwConstants.COOKIE_VM_FIB_TABLE, matches, null);
165 mdsalManager.removeFlow(dpnId, flowEntity);
167 LOG.debug("FIB entry for route {} on dpn {} removed successfully", ipAddress, dpnId);
170 private void removeLFibTableEntry(BigInteger dpnId, long serviceId) {
171 List<MatchInfo> matches = new ArrayList<MatchInfo>();
172 matches.add(new MatchInfo(MatchFieldType.eth_type,
173 new long[] { 0x8847L }));
174 matches.add(new MatchInfo(MatchFieldType.mpls_label, new String[]{Long.toString(serviceId)}));
176 String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, serviceId, "");
178 LOG.debug("removing LFib entry with flow ref {}", flowRef);
180 Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
181 DEFAULT_FIB_FLOW_PRIORITY, flowRef, 0, 0,
182 NwConstants.COOKIE_VM_LFIB_TABLE, matches, null);
184 mdsalManager.removeFlow(dpnId, flowEntity);
186 LOG.debug("LFIB Entry for dpID : {} label : {} removed successfully {}",dpnId, serviceId);
189 private void removeTunnelTableEntry(BigInteger dpnId, long serviceId) {
190 LOG.info("remove terminatingServiceActions called with DpnId = {} and label = {}", dpnId , serviceId);
191 List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
193 mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {BigInteger.valueOf(serviceId)}));
194 Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
195 getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
196 5, String.format("%s:%d","TST Flow Entry ",serviceId), 0, 0,
197 COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, null);
198 mdsalManager.removeFlow(dpnId, flowEntity);
199 LOG.debug("Terminating service Entry for dpID {} : label : {} removed successfully {}",dpnId, serviceId);
202 private void makeTunnelTableEntry(BigInteger dpnId, long serviceId, List<Instruction> customInstructions) {
203 List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
205 LOG.info("create terminatingServiceAction on DpnId = {} and serviceId = {} and actions = {}", dpnId , serviceId);
207 mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {BigInteger.valueOf(serviceId)}));
209 Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
210 getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), 5, String.format("%s:%d","TST Flow Entry ",serviceId),
211 0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)),mkMatches, customInstructions);
213 mdsalManager.installFlow(dpnId, terminatingServiceTableFlowEntity);
216 private long getIpAddress(byte[] rawIpAddress) {
217 return (((rawIpAddress[0] & 0xFF) << (3 * 8)) + ((rawIpAddress[1] & 0xFF) << (2 * 8))
218 + ((rawIpAddress[2] & 0xFF) << (1 * 8)) + (rawIpAddress[3] & 0xFF)) & 0xffffffffL;
221 private void makeLocalFibEntry(long vpnId, BigInteger dpnId, String ipPrefix, List<Instruction> customInstructions) {
222 String values[] = ipPrefix.split("/");
223 String ipAddress = values[0];
224 int prefixLength = (values.length == 1) ? 0 : Integer.parseInt(values[1]);
225 LOG.debug("Adding route to DPN. ip {} masklen {}", ipAddress, prefixLength);
226 InetAddress destPrefix = null;
228 destPrefix = InetAddress.getByName(ipAddress);
229 } catch (UnknownHostException e) {
230 LOG.error("UnknowHostException in addRoute. Failed to add Route for ipPrefix {}", ipAddress, e);
233 List<MatchInfo> matches = new ArrayList<MatchInfo>();
235 matches.add(new MatchInfo(MatchFieldType.metadata, new BigInteger[] {
236 MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID }));
238 matches.add(new MatchInfo(MatchFieldType.eth_type,
239 new long[] { 0x0800L }));
241 if(prefixLength != 0) {
242 matches.add(new MatchInfo(MatchFieldType.ipv4_destination, new String[] {
243 destPrefix.getHostAddress(), Integer.toString(prefixLength) }));
246 String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
249 int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
250 Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef,
251 priority, flowRef, 0, 0,
252 NwConstants.COOKIE_VM_FIB_TABLE, matches, customInstructions);
254 mdsalManager.installFlow(dpnId, flowEntity);
256 LOG.debug("FIB entry for route {} on dpn {} installed successfully", ipAddress, dpnId);
259 private void makeLFibTableEntry(BigInteger dpId, long serviceId, List<Instruction> customInstructions) {
260 List<MatchInfo> matches = new ArrayList<MatchInfo>();
261 matches.add(new MatchInfo(MatchFieldType.eth_type,
262 new long[] { 0x8847L }));
263 matches.add(new MatchInfo(MatchFieldType.mpls_label, new String[]{Long.toString(serviceId)}));
265 List<Instruction> instructions = new ArrayList<Instruction>();
266 List<ActionInfo> actionsInfos = new ArrayList<ActionInfo>();
267 actionsInfos.add(new ActionInfo(ActionType.pop_mpls, new String[]{}));
268 Instruction writeInstruction = new InstructionInfo(InstructionType.write_actions, actionsInfos).buildInstruction(0);
269 instructions.add(writeInstruction);
270 instructions.addAll(customInstructions);
272 // Install the flow entry in L3_LFIB_TABLE
273 String flowRef = getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, serviceId, "");
275 Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
276 DEFAULT_FIB_FLOW_PRIORITY, flowRef, 0, 0,
277 NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
279 mdsalManager.installFlow(dpId, flowEntity);
281 LOG.debug("LFIB Entry for dpID {} : label : {} modified successfully {}",dpId, serviceId );
284 private String getFlowRef(BigInteger dpnId, short tableId, long id, String ipAddress) {
285 return new StringBuilder(64).append(FLOWID_PREFIX).append(dpnId).append(NwConstants.FLOWID_SEPARATOR)
286 .append(tableId).append(NwConstants.FLOWID_SEPARATOR)
287 .append(id).append(NwConstants.FLOWID_SEPARATOR).append(ipAddress).toString();
290 private synchronized void updateVpnToDpnAssociation(long vpnId, BigInteger dpnId, String ipAddr, String vpnName) {
291 LOG.debug("Updating VPN to DPN list for dpn : {} for VPN: {} with ip: {}",
292 dpnId, vpnName, ipAddr);
293 String routeDistinguisher = getVpnRd(dataBroker, vpnName);
294 String rd = (routeDistinguisher == null) ? vpnName : routeDistinguisher;
295 synchronized (vpnName.intern()) {
296 InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
297 Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
298 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses
299 ipAddress = new IpAddressesBuilder().setIpAddress(ipAddr).build();
301 if (dpnInVpn.isPresent()) {
302 MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, id.child(
303 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance
304 .op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses.class,
305 new IpAddressesKey(ipAddr)), ipAddress);
307 MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL,
308 getVpnInstanceOpDataIdentifier(rd),
309 getVpnInstanceOpData(rd, vpnId, vpnName));
310 VpnToDpnListBuilder vpnToDpnList = new VpnToDpnListBuilder().setDpnId(dpnId);
311 List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data
312 .vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses> ipAddresses = new ArrayList<>();
313 ipAddresses.add(ipAddress);
314 MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, id,
315 vpnToDpnList.setIpAddresses(ipAddresses).build());
316 LOG.debug("populate FIB on new dpn {} for VPN {}", dpnId, vpnName);
317 fibManager.populateFibOnNewDpn(dpnId, vpnId, rd, null);
322 private synchronized void removeFromVpnDpnAssociation(long vpnId, BigInteger dpnId, String ipAddr, String vpnName) {
323 LOG.debug("Removing association of VPN to DPN list for dpn : {} for VPN: {} with ip: {}",
324 dpnId, vpnName, ipAddr);
325 String routeDistinguisher = getVpnRd(dataBroker, vpnName);
326 String rd = (routeDistinguisher == null) ? vpnName : routeDistinguisher;
327 synchronized (vpnName.intern()) {
328 InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
329 Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
330 if (dpnInVpn.isPresent()) {
331 List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data
332 .vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses> ipAddresses = dpnInVpn.get().getIpAddresses();
333 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses
334 ipAddress = new IpAddressesBuilder().setIpAddress(ipAddr).build();
336 if (ipAddresses != null && ipAddresses.remove(ipAddress)) {
337 if (ipAddresses.isEmpty()) {
338 List<VpnInterfaces> vpnInterfaces = dpnInVpn.get().getVpnInterfaces();
339 if (vpnInterfaces == null || vpnInterfaces.isEmpty()) {
341 LOG.debug("Cleaning up dpn {} from VPN {}", dpnId, vpnName);
342 MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
343 fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd, null);
346 delete(dataBroker, LogicalDatastoreType.OPERATIONAL, id.child(
347 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data
348 .vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses.class,
349 new IpAddressesKey(ipAddr)));
356 //TODO: Below Util methods to be removed once VpnUtil methods are exposed in api bundle
357 public static String getVpnRd(DataBroker broker, String vpnName) {
359 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance> id
360 = getVpnInstanceToVpnIdIdentifier(vpnName);
361 Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance> vpnInstance
362 = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
365 if(vpnInstance.isPresent()) {
366 rd = vpnInstance.get().getVrfId();
371 static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance>
372 getVpnInstanceToVpnIdIdentifier(String vpnName) {
373 return InstanceIdentifier.builder(VpnInstanceToVpnId.class)
374 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance.class,
375 new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstanceKey(vpnName)).build();
379 static InstanceIdentifier<VpnToDpnList> getVpnToDpnListIdentifier(String rd, BigInteger dpnId) {
380 return InstanceIdentifier.builder(VpnInstanceOpData.class)
381 .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(rd))
382 .child(VpnToDpnList.class, new VpnToDpnListKey(dpnId)).build();
385 static InstanceIdentifier<VpnInstanceOpDataEntry> getVpnInstanceOpDataIdentifier(String rd) {
386 return InstanceIdentifier.builder(VpnInstanceOpData.class)
387 .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(rd)).build();
390 static VpnInstanceOpDataEntry getVpnInstanceOpData(String rd, long vpnId, String vpnName) {
391 return new VpnInstanceOpDataEntryBuilder().setVrfId(rd).setVpnId(vpnId).setVpnInstanceName(vpnName).build();
394 static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType,
395 InstanceIdentifier<T> path) {
396 WriteTransaction tx = broker.newWriteOnlyTransaction();
397 tx.delete(datastoreType, path);
401 static long getVpnId(DataBroker broker, String vpnName) {
403 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance> id
404 = getVpnInstanceToVpnIdIdentifier(vpnName);
405 Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance> vpnInstance
406 = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
409 if(vpnInstance.isPresent()) {
410 vpnId = vpnInstance.get().getVpnId();