2 * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.vpnservice.impl;
11 import java.util.HashMap;
14 import org.opendaylight.nic.mapping.api.IntentMappingService;
16 import com.google.common.base.Preconditions;
18 public class MappingServiceManager {
20 private IntentMappingService intentMappingService;
21 private String IP_PREFIX_PROPERTY = "ip_prefix";
22 private String SWITCH_PORT_ID_PROPERTY = "switch_port";
23 private String MPLS_LABEL_PROPERTY = "mpls_label";
24 private String NEXT_HOP_PROPERTY = "next_hop";
26 public MappingServiceManager(IntentMappingService intentMappingService) {
27 Preconditions.checkNotNull(intentMappingService);
28 this.intentMappingService = intentMappingService;
35 * Ip prefix of the member
37 * Switch ID and port ID (i.e. openflow:1:2)
39 * MPLS label, if needed
41 * Next hop in the route
43 public void add(final String siteName, final String ipPrefix, final String switchPortId, final Long mplsLabel,
44 final String nextHop) {
45 Preconditions.checkNotNull(siteName);
46 Preconditions.checkNotNull(ipPrefix);
47 Preconditions.checkNotNull(switchPortId);
49 Map<String, String> objs = new HashMap<>();
50 objs.put(IP_PREFIX_PROPERTY, ipPrefix);
51 objs.put(SWITCH_PORT_ID_PROPERTY, switchPortId);
53 if (mplsLabel != null)
54 objs.put(MPLS_LABEL_PROPERTY, String.valueOf(mplsLabel));
56 objs.put(NEXT_HOP_PROPERTY, nextHop);
58 intentMappingService.add(siteName, objs);
64 * @return Map of parameters related to the member
66 public Map<String, String> get(String siteName) {
67 return intentMappingService.get(siteName);
73 * @return Return true if transaction succeed, otherwise false
75 public boolean delete(String siteName) {
77 // TODO: Implement delete() in mapping service
78 // By now, it's going to overwrite data for this key
79 intentMappingService.add(siteName, null);
81 } catch (Exception e) {