Fixes for DVR
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / info / container / states / PortRouteState.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.info.container.states;
9
10 import com.google.common.collect.Lists;
11
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19
20 /**
21  * Created by Shakib Ahmed on 7/17/17.
22  */
23 public class PortRouteState {
24     private HashMap<Ipv4Address, String> ipToSubnetUuidMapper;
25     private HashMap<Ipv4Address, Long> ipToRouteIdMapper;
26     private Long vrfId;
27
28     public PortRouteState(long vrfId) {
29         ipToRouteIdMapper = new HashMap<>();
30         ipToSubnetUuidMapper = new HashMap<>();
31         this.vrfId = vrfId;
32     }
33
34     public long getVrfId() {
35         return this.vrfId;
36     }
37
38     public void addRouteInfo(Ipv4Address ip, Long routeId, String ipSubnetUuid) {
39         ipToRouteIdMapper.put(ip, routeId);
40         ipToSubnetUuidMapper.put(ip, ipSubnetUuid);
41     }
42
43     public Long getRouteIdOfIp(Ipv4Address interfaceIp) {
44         return ipToRouteIdMapper.get(interfaceIp);
45     }
46
47     public String getSubnetUuidOfIp(Ipv4Address interfaceIp) {
48         return ipToSubnetUuidMapper.get(interfaceIp);
49     }
50
51     public void removeIp(Ipv4Address ip) {
52         ipToRouteIdMapper.remove(ip);
53         ipToSubnetUuidMapper.remove(ip);
54     }
55
56     public List<Ipv4Address> getAllIps() {
57         return new ArrayList<>(ipToRouteIdMapper.keySet());
58     }
59
60     public boolean isPortRouteStateEmpty() {
61         return (ipToRouteIdMapper.size() == 0 && ipToSubnetUuidMapper.size() == 0);
62     }
63
64     @Override public String toString() {
65         return "PortRouteState= {vrfId= " + vrfId + ", ipToSubnetUuidMapper= " + ipToSubnetUuidMapper + ", ipToRouteIdMapper= " + ipToRouteIdMapper + "}";
66     }
67 }