1185cd9817a2bfa1639f48ab320396daebf22e27
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / mappers / HostIdToInterfaceInfoMapper.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.groupbasedpolicy.renderer.vpp.lisp.InterfaceInfo;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
12
13 import java.util.HashMap;
14
15 /**
16  * Created by Shakib Ahmed on 6/23/17.
17  */
18 public class HostIdToInterfaceInfoMapper {
19
20     public enum InterfaceType {
21         PUBLIC
22     }
23
24     HashMap<String, HashMap<InterfaceType, InterfaceInfo>> hostIdToInterfaceInfoMapper;
25
26     private HostIdToInterfaceInfoMapper() {
27         hostIdToInterfaceInfoMapper = new HashMap<>();
28     }
29
30     private static final HostIdToInterfaceInfoMapper INSTANCE = new HostIdToInterfaceInfoMapper();
31
32     public static HostIdToInterfaceInfoMapper getInstance() {
33         return INSTANCE;
34     }
35
36     public void addInterfaceInfo(String hostId,
37                                  InterfaceType interfaceType,
38                                  String interfaceName,
39                                  IpAddress interfaceIp) {
40         HashMap<InterfaceType, InterfaceInfo> typeToInterfaceInfoMapper =
41                 hostIdToInterfaceInfoMapper.computeIfAbsent(hostId, id -> new HashMap<>());
42
43         typeToInterfaceInfoMapper.put(interfaceType, new InterfaceInfo(interfaceName, interfaceIp));
44     }
45
46     public InterfaceInfo getInterfaceInfo(String hostId, InterfaceType interfaceType) {
47
48         if (!hostIdToInterfaceInfoMapper.containsKey(hostId)) {
49             return null;
50         }
51
52         return hostIdToInterfaceInfoMapper.get(hostId).get(interfaceType);
53     }
54 }