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;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import com.google.common.base.Preconditions;
20 public class MappingServiceManager {
22 private static final Logger LOG = LoggerFactory.getLogger(MappingServiceManager.class);
23 private IntentMappingService intentMappingService;
24 private String IP_PREFIX_PROPERTY = "ip_prefix";
25 private String SWITCH_PORT_ID_PROPERTY = "switch_port";
26 private String MPLS_LABEL_PROPERTY = "mpls_label";
27 private String NEXT_HOP_PROPERTY = "next_hop";
29 public MappingServiceManager(IntentMappingService intentMappingService) {
30 Preconditions.checkNotNull(intentMappingService);
31 this.intentMappingService = intentMappingService;
38 * Ip prefix of the member
40 * Switch ID and port ID (i.e. openflow:1:2)
42 * MPLS label, if needed
44 * Next hop in the route
46 public void add(final String siteName, final String ipPrefix, final String switchPortId, final Long mplsLabel,
47 final String nextHop) {
48 Preconditions.checkNotNull(siteName);
49 Preconditions.checkNotNull(ipPrefix);
50 Preconditions.checkNotNull(switchPortId);
52 Map<String, String> objs = new HashMap<>();
53 objs.put(IP_PREFIX_PROPERTY, ipPrefix);
54 objs.put(SWITCH_PORT_ID_PROPERTY, switchPortId);
56 if (mplsLabel != null)
57 objs.put(MPLS_LABEL_PROPERTY, String.valueOf(mplsLabel));
59 objs.put(NEXT_HOP_PROPERTY, nextHop);
61 intentMappingService.add(siteName, objs);
67 * @return Map of parameters related to the member
69 public Map<String, String> get(String siteName) {
70 return intentMappingService.get(siteName);
76 * @return Return true if transaction succeed, otherwise false
78 public boolean delete(String siteName) {
80 // TODO: Implement delete() in mapping service
81 // By now, it's going to overwrite data for this key
82 intentMappingService.add(siteName, null);
84 } catch (Exception e) {
85 LOG.error("Error deleting from NIC's mapping service {}", e);