Vxlan/Gre co-existence,Alarms,tunnelstate,TR fixes
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / cli / SubnetObject.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  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.vpnservice.itm.cli;
9
10 import java.util.Map;
11
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.SubnetsBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.rev150701.transport.zones.transport.zone.SubnetsKey;
16 import org.opendaylight.yangtools.yang.binding.Augmentation;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18
19 public class SubnetObject {
20     private IpAddress _gatewayIp;
21     private SubnetsKey _key;
22     private IpPrefix _prefix;
23     private java.lang.Integer _vlanId;
24
25     public SubnetObject(IpAddress gWIP, SubnetsKey key, IpPrefix mask, Integer vlanId) {
26         _gatewayIp = gWIP;
27         _key = key;
28         _prefix = mask;
29         try {
30             if (vlanId != null) {
31                 checkVlanIdRange(vlanId);
32             }
33         } catch (IllegalArgumentException e) {
34             System.out.println("Invalid VlanID. expected: 0 to 4095");
35         }
36         _vlanId = vlanId;
37     }
38
39     public IpAddress get_gatewayIp() {
40         return _gatewayIp;
41     }
42
43     public SubnetsKey get_key() {
44         return _key;
45     }
46
47     public IpPrefix get_prefix() {
48         return _prefix;
49     }
50
51     public java.lang.Integer get_vlanId() {
52         return _vlanId;
53     }
54
55     private int hash = 0;
56     private volatile boolean hashValid = false;
57
58     @Override
59     public int hashCode() {
60         if (hashValid) {
61             return hash;
62         }
63
64         final int prime = 31;
65         int result = 1;
66         result = prime * result + ((_gatewayIp == null) ? 0 : _gatewayIp.hashCode());
67         result = prime * result + ((_key == null) ? 0 : _key.hashCode());
68         result = prime * result + ((_prefix == null) ? 0 : _prefix.hashCode());
69         result = prime * result + ((_vlanId == null) ? 0 : _vlanId.hashCode());
70         hash = result;
71         hashValid = true;
72         return result;
73     }
74
75     @Override
76     public boolean equals(java.lang.Object obj) {
77         if (this == obj) {
78             return true;
79         }
80         if (!(obj instanceof SubnetObject)) {
81             return false;
82         }
83         SubnetObject other = (SubnetObject) obj;
84         if (_gatewayIp == null) {
85             if (other.get_gatewayIp() != null) {
86                 return false;
87             }
88         } else if (!_gatewayIp.equals(other.get_gatewayIp())) {
89             return false;
90         }
91         if (_key == null) {
92             if (other.get_key() != null) {
93                 return false;
94             }
95         } else if (!_key.equals(other.get_key())) {
96             return false;
97         }
98         if (_prefix == null) {
99             if (other.get_prefix() != null) {
100                 return false;
101             }
102         } else if (!_prefix.equals(other.get_prefix())) {
103             return false;
104         }
105         if (_vlanId == null) {
106             if (other.get_vlanId() != null) {
107                 return false;
108             }
109         } else if (!_vlanId.equals(other.get_vlanId())) {
110             return false;
111         }
112         return true;
113     }
114
115     @Override
116     public java.lang.String toString() {
117         java.lang.StringBuilder builder = new java.lang.StringBuilder("Subnets [");
118         boolean first = true;
119
120         if (_gatewayIp != null) {
121             if (first) {
122                 first = false;
123             } else {
124                 builder.append(", ");
125             }
126             builder.append("_gatewayIp=");
127             builder.append(_gatewayIp);
128         }
129         if (_key != null) {
130             if (first) {
131                 first = false;
132             } else {
133                 builder.append(", ");
134             }
135             builder.append("_key=");
136             builder.append(_key);
137         }
138         if (_prefix != null) {
139             if (first) {
140                 first = false;
141             } else {
142                 builder.append(", ");
143             }
144             builder.append("_prefix=");
145             builder.append(_prefix);
146         }
147         if (_vlanId != null) {
148             if (first) {
149                 first = false;
150             } else {
151                 builder.append(", ");
152             }
153             builder.append("_vlanId=");
154             builder.append(_vlanId);
155         }
156         return builder.append(']').toString();
157     }
158
159     private static void checkVlanIdRange(final int value) {
160         if (value >= 0 && value <= 4095) {
161             return;
162         }
163         throw new IllegalArgumentException(String.format("Invalid range: %s, expected: [[0?4095]].", value));
164     }
165 }