7765dbb0efc8ecf7e1e74f5d73b36bacaf208827
[netvirt.git] / vpnservice / fibmanager / fibmanager-impl / src / main / java / org / opendaylight / netvirt / fibmanager / FibRpcServiceImpl.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.fibmanager;
9
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;
13
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.MDSALUtil;
27 import org.opendaylight.genius.mdsalutil.MatchInfo;
28 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
29 import org.opendaylight.genius.mdsalutil.NwConstants;
30 import org.opendaylight.genius.mdsalutil.actions.ActionPopMpls;
31 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
32 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
33 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
34 import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination;
35 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
36 import org.opendaylight.genius.mdsalutil.matches.MatchMplsLabel;
37 import org.opendaylight.genius.mdsalutil.matches.MatchTunnelId;
38 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CleanupDpnForVpnInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.CreateFibEntryInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.FibRpcService;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.PopulateFibOnDpnInput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fib.rpc.rev160121.RemoveFibEntryInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceOpData;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.VpnInstanceToVpnId;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntryKey;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnListKey;
54 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;
55 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;
56 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;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstanceKey;
59 import org.opendaylight.yangtools.yang.binding.DataObject;
60 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
61 import org.opendaylight.yangtools.yang.common.RpcResult;
62 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
65
66 public class FibRpcServiceImpl implements FibRpcService {
67     private static final Logger LOG = LoggerFactory.getLogger(FibRpcServiceImpl.class);
68     private final DataBroker dataBroker;
69     private final IMdsalApiManager mdsalManager;
70     private final IFibManager fibManager;
71
72     public FibRpcServiceImpl(final DataBroker dataBroker, final IMdsalApiManager mdsalManager,
73                              final IFibManager fibManager) {
74         this.dataBroker = dataBroker;
75         this.mdsalManager = mdsalManager;
76         this.fibManager = fibManager;
77     }
78
79     /**
80      * To install FIB routes on specified dpn with given instructions.
81      */
82     @Override
83     public Future<RpcResult<Void>> createFibEntry(CreateFibEntryInput input) {
84
85         BigInteger dpnId = input.getSourceDpid();
86         String vpnName = input.getVpnName();
87         long vpnId = getVpnId(dataBroker, vpnName);
88         String vpnRd = getVpnRd(dataBroker, vpnName);
89         String ipAddress = input.getIpAddress();
90         LOG.info("Create custom FIB entry - {} on dpn {} for VPN {} ", ipAddress, dpnId, vpnName);
91         List<Instruction> instructions = input.getInstruction();
92         LOG.info("ADD: Adding Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
93         makeLocalFibEntry(vpnId, dpnId, ipAddress, instructions);
94         updateVpnToDpnAssociation(vpnId, dpnId, ipAddress, vpnName);
95         LOG.info("ADD: Added Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
96         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
97     }
98
99     /**
100      * To remove FIB/LFIB/TST routes from specified dpn.
101      */
102     @Override
103     public Future<RpcResult<Void>> removeFibEntry(RemoveFibEntryInput input) {
104         BigInteger dpnId = input.getSourceDpid();
105         String vpnName = input.getVpnName();
106         long vpnId = getVpnId(dataBroker, vpnName);
107         String vpnRd = getVpnRd(dataBroker, vpnName);
108         long serviceId = input.getServiceId();
109         String ipAddress = input.getIpAddress();
110
111         LOG.info("Delete custom FIB entry - {} on dpn {} for VPN {} ", ipAddress, dpnId, vpnName);
112         LOG.info("REMOVE: Removing Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
113         removeLocalFibEntry(dpnId, vpnId, ipAddress);
114         //removeLFibTableEntry(dpnId, serviceId);
115         //removeTunnelTableEntry(dpnId, serviceId);
116         removeFromVpnDpnAssociation(vpnId, dpnId, ipAddress, vpnName);
117         LOG.info("REMOVE: Removed Custom Fib Entry rd {} prefix {} label {}", vpnRd, ipAddress, input.getServiceId());
118
119         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
120     }
121
122
123     @Override
124     public Future<RpcResult<Void>> populateFibOnDpn(PopulateFibOnDpnInput input) {
125         fibManager.populateFibOnNewDpn(input.getDpid(), input.getVpnId(), input.getRd(), null);
126         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
127     }
128
129     @Override
130     public Future<RpcResult<Void>> cleanupDpnForVpn(CleanupDpnForVpnInput input) {
131         fibManager.cleanUpDpnForVpn(input.getDpid(), input.getVpnId(), input.getRd(), null);
132         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
133     }
134
135     private void removeLocalFibEntry(BigInteger dpnId, long vpnId, String ipPrefix) {
136         String[] values = ipPrefix.split("/");
137         String ipAddress = values[0];
138         int prefixLength = (values.length == 1) ? 0 : Integer.parseInt(values[1]);
139         LOG.debug("Removing route from DPN. ip {} masklen {}", ipAddress, prefixLength);
140         InetAddress destPrefix = null;
141         try {
142             destPrefix = InetAddress.getByName(ipAddress);
143         } catch (UnknownHostException e) {
144             LOG.error("UnknowHostException in removeRoute. Failed  to remove Route for ipPrefix {}", ipAddress, e);
145             return;
146         }
147         List<MatchInfo> matches = new ArrayList<MatchInfo>();
148
149         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
150
151         matches.add(MatchEthernetType.IPV4);
152
153         if (prefixLength != 0) {
154             matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
155         }
156
157         String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
158
159
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);
164
165         mdsalManager.removeFlow(dpnId, flowEntity);
166
167         LOG.debug("FIB entry for route {} on dpn {} removed successfully", ipAddress, dpnId);
168     }
169
170     private void removeLFibTableEntry(BigInteger dpnId, long serviceId) {
171         List<MatchInfo> matches = new ArrayList<MatchInfo>();
172         matches.add(MatchEthernetType.MPLS_UNICAST);
173         matches.add(new MatchMplsLabel(serviceId));
174
175         String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, serviceId, "");
176
177         LOG.debug("removing LFib entry with flow ref {}", flowRef);
178
179         Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
180             DEFAULT_FIB_FLOW_PRIORITY, flowRef, 0, 0,
181             NwConstants.COOKIE_VM_LFIB_TABLE, matches, null);
182
183         mdsalManager.removeFlow(dpnId, flowEntity);
184
185         LOG.debug("LFIB Entry for dpID : {} label : {} removed successfully {}", dpnId, serviceId);
186     }
187
188     private void removeTunnelTableEntry(BigInteger dpnId, long serviceId) {
189         LOG.info("remove terminatingServiceActions called with DpnId = {} and label = {}", dpnId, serviceId);
190         List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
191         // Matching metadata
192         mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
193         Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
194             getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""),
195             5, String.format("%s:%d", "TST Flow Entry ", serviceId), 0, 0,
196             COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, null);
197         mdsalManager.removeFlow(dpnId, flowEntity);
198         LOG.debug("Terminating service Entry for dpID {} : label : {} removed successfully {}", dpnId, serviceId);
199     }
200
201     private void makeTunnelTableEntry(BigInteger dpnId, long serviceId, List<Instruction> customInstructions) {
202         List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
203
204         LOG.info("create terminatingServiceAction on DpnId = {} and serviceId = {} and actions = {}", dpnId, serviceId);
205
206         mkMatches.add(new MatchTunnelId(BigInteger.valueOf(serviceId)));
207
208         Flow terminatingServiceTableFlowEntity = MDSALUtil.buildFlowNew(NwConstants.INTERNAL_TUNNEL_TABLE,
209             getFlowRef(dpnId, NwConstants.INTERNAL_TUNNEL_TABLE, serviceId, ""), 5,
210             String.format("%s:%d", "TST Flow Entry ", serviceId),
211             0, 0, COOKIE_TUNNEL.add(BigInteger.valueOf(serviceId)), mkMatches, customInstructions);
212
213         mdsalManager.installFlow(dpnId, terminatingServiceTableFlowEntity);
214     }
215
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;
219     }
220
221     private void makeLocalFibEntry(long vpnId, BigInteger dpnId, String ipPrefix,
222                                    List<Instruction> customInstructions) {
223         String[] values = ipPrefix.split("/");
224         String ipAddress = values[0];
225         int prefixLength = (values.length == 1) ? 0 : Integer.parseInt(values[1]);
226         LOG.debug("Adding route to DPN. ip {} masklen {}", ipAddress, prefixLength);
227         InetAddress destPrefix = null;
228         try {
229             destPrefix = InetAddress.getByName(ipAddress);
230         } catch (UnknownHostException e) {
231             LOG.error("UnknowHostException in addRoute. Failed  to add Route for ipPrefix {}", ipAddress, e);
232             return;
233         }
234         List<MatchInfo> matches = new ArrayList<MatchInfo>();
235
236         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
237
238         matches.add(MatchEthernetType.IPV4);
239
240         if (prefixLength != 0) {
241             matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
242         }
243
244         String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
245
246
247         int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
248         Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef,
249             priority, flowRef, 0, 0,
250             NwConstants.COOKIE_VM_FIB_TABLE, matches, customInstructions);
251
252         mdsalManager.installFlow(dpnId, flowEntity);
253
254         LOG.debug("FIB entry for route {} on dpn {} installed successfully", ipAddress, dpnId);
255     }
256
257     private void makeLFibTableEntry(BigInteger dpId, long serviceId, List<Instruction> customInstructions) {
258         List<MatchInfo> matches = new ArrayList<MatchInfo>();
259         matches.add(MatchEthernetType.MPLS_UNICAST);
260         matches.add(new MatchMplsLabel(serviceId));
261
262         List<Instruction> instructions = new ArrayList<Instruction>();
263         List<ActionInfo> actionsInfos = new ArrayList<ActionInfo>();
264         actionsInfos.add(new ActionPopMpls());
265         Instruction writeInstruction = new InstructionApplyActions(actionsInfos).buildInstruction(0);
266         instructions.add(writeInstruction);
267         instructions.addAll(customInstructions);
268
269         // Install the flow entry in L3_LFIB_TABLE
270         String flowRef = getFlowRef(dpId, NwConstants.L3_LFIB_TABLE, serviceId, "");
271
272         Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
273             DEFAULT_FIB_FLOW_PRIORITY, flowRef, 0, 0,
274             NwConstants.COOKIE_VM_LFIB_TABLE, matches, instructions);
275
276         mdsalManager.installFlow(dpId, flowEntity);
277
278         LOG.debug("LFIB Entry for dpID {} : label : {} modified successfully {}", dpId, serviceId);
279     }
280
281     private String getFlowRef(BigInteger dpnId, short tableId, long id, String ipAddress) {
282         return new StringBuilder(64).append(FLOWID_PREFIX).append(dpnId).append(NwConstants.FLOWID_SEPARATOR)
283             .append(tableId).append(NwConstants.FLOWID_SEPARATOR)
284             .append(id).append(NwConstants.FLOWID_SEPARATOR).append(ipAddress).toString();
285     }
286
287     private synchronized void updateVpnToDpnAssociation(long vpnId, BigInteger dpnId, String ipAddr, String vpnName) {
288         LOG.debug("Updating VPN to DPN list for dpn : {} for VPN: {} with ip: {}",
289             dpnId, vpnName, ipAddr);
290         String routeDistinguisher = getVpnRd(dataBroker, vpnName);
291         String rd = (routeDistinguisher == null) ? vpnName : routeDistinguisher;
292         synchronized (vpnName.intern()) {
293             InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
294             Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
295             org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn
296                 .instance.op.data.entry.vpn.to.dpn.list.IpAddresses ipAddress =
297                 new IpAddressesBuilder().setIpAddress(ipAddr).build();
298
299             if (dpnInVpn.isPresent()) {
300                 MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, id.child(
301                     org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance
302                         .op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses.class,
303                     new IpAddressesKey(ipAddr)), ipAddress);
304             } else {
305                 MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL,
306                     getVpnInstanceOpDataIdentifier(rd),
307                     getVpnInstanceOpData(rd, vpnId, vpnName));
308                 VpnToDpnListBuilder vpnToDpnList = new VpnToDpnListBuilder().setDpnId(dpnId);
309                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data
310                     .vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses> ipAddresses = new ArrayList<>();
311                 ipAddresses.add(ipAddress);
312                 MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, id,
313                     vpnToDpnList.setIpAddresses(ipAddresses).build());
314                 LOG.debug("populate FIB on new dpn {} for VPN {}", dpnId, vpnName);
315                 fibManager.populateFibOnNewDpn(dpnId, vpnId, rd, null);
316             }
317         }
318     }
319
320     private synchronized void removeFromVpnDpnAssociation(long vpnId, BigInteger dpnId, String ipAddr, String vpnName) {
321         LOG.debug("Removing association of VPN to DPN list for dpn : {} for VPN: {} with ip: {}",
322             dpnId, vpnName, ipAddr);
323         String routeDistinguisher = getVpnRd(dataBroker, vpnName);
324         String rd = (routeDistinguisher == null) ? vpnName : routeDistinguisher;
325         synchronized (vpnName.intern()) {
326             InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
327             Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
328             if (dpnInVpn.isPresent()) {
329                 List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data
330                     .vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses> ipAddresses =
331                     dpnInVpn.get().getIpAddresses();
332                 org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn
333                     .instance.op.data.entry.vpn.to.dpn.list.IpAddresses ipAddress =
334                     new IpAddressesBuilder().setIpAddress(ipAddr).build();
335
336                 if (ipAddresses != null && ipAddresses.remove(ipAddress)) {
337                     if (ipAddresses.isEmpty()) {
338                         List<VpnInterfaces> vpnInterfaces = dpnInVpn.get().getVpnInterfaces();
339                         if (vpnInterfaces == null || vpnInterfaces.isEmpty()) {
340                             //Clean up the dpn
341                             LOG.debug("Cleaning up dpn {} from VPN {}", dpnId, vpnName);
342                             MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
343                             fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd, null);
344                         }
345                     } else {
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)));
350                     }
351                 }
352             }
353         }
354     }
355
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) {
358         InstanceIdentifier<VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
359         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id).transform(VpnInstance::getVrfId).orNull();
360     }
361
362     static InstanceIdentifier<VpnInstance> getVpnInstanceToVpnIdIdentifier(String vpnName) {
363         return InstanceIdentifier.builder(VpnInstanceToVpnId.class)
364             .child(VpnInstance.class, new VpnInstanceKey(vpnName)).build();
365     }
366
367
368     static InstanceIdentifier<VpnToDpnList> getVpnToDpnListIdentifier(String rd, BigInteger dpnId) {
369         return InstanceIdentifier.builder(VpnInstanceOpData.class)
370             .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(rd))
371             .child(VpnToDpnList.class, new VpnToDpnListKey(dpnId)).build();
372     }
373
374     static InstanceIdentifier<VpnInstanceOpDataEntry> getVpnInstanceOpDataIdentifier(String rd) {
375         return InstanceIdentifier.builder(VpnInstanceOpData.class)
376             .child(VpnInstanceOpDataEntry.class, new VpnInstanceOpDataEntryKey(rd)).build();
377     }
378
379     static VpnInstanceOpDataEntry getVpnInstanceOpData(String rd, long vpnId, String vpnName) {
380         return new VpnInstanceOpDataEntryBuilder().setVrfId(rd).setVpnId(vpnId).setVpnInstanceName(vpnName).build();
381     }
382
383     static <T extends DataObject> void delete(DataBroker broker, LogicalDatastoreType datastoreType,
384                                               InstanceIdentifier<T> path) {
385         WriteTransaction tx = broker.newWriteOnlyTransaction();
386         tx.delete(datastoreType, path);
387         tx.submit();
388     }
389
390     static long getVpnId(DataBroker broker, String vpnName) {
391         InstanceIdentifier<VpnInstance> id = getVpnInstanceToVpnIdIdentifier(vpnName);
392         return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id).transform(VpnInstance::getVpnId).or(-1L);
393     }
394
395
396 }