Bug 8599 - updating metadata endpoints
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / mappers / InterfaceNameToRouteInfoMapper.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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
11
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
15
16 /**
17  * Created by Shakib Ahmed on 5/26/17.
18  */
19 public class InterfaceNameToRouteInfoMapper {
20     HashMap<String, StaticRouteInfoMapper> interfaceNameToStaticRouteMapper;
21
22     public InterfaceNameToRouteInfoMapper() {
23         interfaceNameToStaticRouteMapper = new HashMap<>();
24     }
25
26     public boolean routeAlreadyExists(String interfaceName, Ipv4Address ip) {
27         StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
28
29         if (staticRouteInfoMapper == null) {
30             return false;
31         }
32
33         return staticRouteInfoMapper.routeWithIpExists(ip);
34     }
35
36     public void addRouteForInterface(String interfaceName, Ipv4Address ip, Long routeId) {
37         StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
38
39         if (staticRouteInfoMapper == null) {
40             staticRouteInfoMapper = new StaticRouteInfoMapper();
41             interfaceNameToStaticRouteMapper.put(interfaceName, staticRouteInfoMapper);
42         }
43
44         staticRouteInfoMapper.addIpRouteForInterface(ip, routeId);
45     }
46
47     public List<Long> getRoutingIdsAssociatedWithInterface(String interfaceName) {
48         StaticRouteInfoMapper staticRouteInfoMapper = interfaceNameToStaticRouteMapper.get(interfaceName);
49
50         return staticRouteInfoMapper == null ? new ArrayList<>() : staticRouteInfoMapper.getAllRoutingIds();
51     }
52
53     public void clearStaticRoutesForInterface(String interfaceName) {
54         interfaceNameToStaticRouteMapper.remove(interfaceName);
55     }
56 }