Fixes for DVR
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / info / container / states / SubnetState.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 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 import java.util.HashSet;
15 import java.util.Set;
16
17 /**
18  * Created by Shakib Ahmed on 7/17/17.
19  */
20 public class SubnetState {
21     private String gwInterfaceName;
22     private Set<Ipv4Address> ipsInSubnet;
23
24     private static final Logger LOG = LoggerFactory.getLogger(SubnetState.class);
25
26
27     public SubnetState() {
28         ipsInSubnet = new HashSet<>();
29     }
30
31     public boolean isGwConfigured() {
32         return gwInterfaceName != null && !gwInterfaceName.isEmpty();
33     }
34
35     public String getGwInterfaceName() {
36         return gwInterfaceName;
37     }
38
39     public void setGwInterfaceName(String gwInterfaceName) {
40         this.gwInterfaceName = gwInterfaceName;
41     }
42
43     public boolean hasIpsInSubnet() {
44         return !ipsInSubnet.isEmpty();
45     }
46
47     public void addNewIp(Ipv4Address portIp) {
48         ipsInSubnet.add(portIp);
49         LOG.trace("SubnetState -> added IP: {} to SubnetState: {}", portIp, this);
50     }
51
52     public boolean isIpPresent(Ipv4Address portIp) {
53         return ipsInSubnet.contains(portIp);
54     }
55
56     public void removeIp(Ipv4Address portIp) {
57         ipsInSubnet.remove(portIp);
58         LOG.trace("SubnetState -> removed IP: {} from SubnetState: {}", portIp, this);
59     }
60
61     public Set<Ipv4Address> getIpsInSubnet() {
62         return ipsInSubnet;
63     }
64
65     @Override public String toString() {
66         return "SubnetState{" + "gwInterfaceName='" + gwInterfaceName + '\'' + ", ipsInSubnet=" + ipsInSubnet + '}';
67     }
68 }