Bug 8599 - updating metadata endpoints
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / mappers / InterfaceNameToStaticInfoMapper.java
1 /*
2  * Copyright (c) 2017 Cisco Systems. 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.groupbasedpolicy.renderer.vpp.lisp.mappers;
9
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;
12
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
16
17 /**
18  * Created by Shakib Ahmed on 5/26/17.
19  */
20 public class InterfaceNameToStaticInfoMapper {
21     HashMap<String, StaticRouteInfoMapper> interfaceNameToStaticRouteMapper;
22
23     private static final InterfaceNameToStaticInfoMapper INSTANCE = new InterfaceNameToStaticInfoMapper();
24
25     private InterfaceNameToStaticInfoMapper() {
26         interfaceNameToStaticRouteMapper = new HashMap<>();
27     }
28
29     public static InterfaceNameToStaticInfoMapper getInstance() {
30         return INSTANCE;
31     }
32
33     public boolean routeAlreadyExists(String interfaceName, Ipv4Address ip) {
34         StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
35
36         if (staticRouteInfoMapper == null) {
37             return false;
38         }
39
40         return staticRouteInfoMapper.routeWithIpExists(ip);
41     }
42
43     public void addRouteForInterface(String interfaceName, Ipv4Address ip, Long routeId) {
44         StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
45
46         if (staticRouteInfoMapper == null) {
47             staticRouteInfoMapper = new StaticRouteInfoMapper();
48             interfaceNameToStaticRouteMapper.put(interfaceName, staticRouteInfoMapper);
49         }
50
51         staticRouteInfoMapper.addIpRouteForInterface(ip, routeId);
52     }
53
54     public List<Long> getRoutingIdsAssociatedWithInterface(String interfaceName) {
55         StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
56
57         return staticRouteInfoMapper == null ? new ArrayList<>() : staticRouteInfoMapper.getAllRoutingIds();
58     }
59
60     public void clearStaticRoutesForInterface(String interfaceName) {
61         interfaceNameToStaticRouteMapper.remove(interfaceName);
62     }
63 }