2 * Copyright (c) 2017 Cisco Systems. 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.groupbasedpolicy.renderer.vpp.lisp.mappers;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
18 * Created by Shakib Ahmed on 5/26/17.
20 public class InterfaceNameToStaticInfoMapper {
21 HashMap<String, StaticRouteInfoMapper> interfaceNameToStaticRouteMapper;
23 private static final InterfaceNameToStaticInfoMapper INSTANCE = new InterfaceNameToStaticInfoMapper();
25 private InterfaceNameToStaticInfoMapper() {
26 interfaceNameToStaticRouteMapper = new HashMap<>();
29 public static InterfaceNameToStaticInfoMapper getInstance() {
33 public boolean routeAlreadyExists(String interfaceName, Ipv4Address ip) {
34 StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
36 if (staticRouteInfoMapper == null) {
40 return staticRouteInfoMapper.routeWithIpExists(ip);
43 public void addRouteForInterface(String interfaceName, Ipv4Address ip, Long routeId) {
44 StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
46 if (staticRouteInfoMapper == null) {
47 staticRouteInfoMapper = new StaticRouteInfoMapper();
48 interfaceNameToStaticRouteMapper.put(interfaceName, staticRouteInfoMapper);
51 staticRouteInfoMapper.addIpRouteForInterface(ip, routeId);
54 public List<Long> getRoutingIdsAssociatedWithInterface(String interfaceName) {
55 StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
57 return staticRouteInfoMapper == null ? new ArrayList<>() : staticRouteInfoMapper.getAllRoutingIds();
60 public void clearStaticRoutesForInterface(String interfaceName) {
61 interfaceNameToStaticRouteMapper.remove(interfaceName);