a08f0ff7d171942ee097364430d44486a1ecbc06
[netvirt.git] / vpnservice / ipv6service / impl / src / main / java / org / opendaylight / netvirt / ipv6service / VirtualSubnet.java
1 /*
2  * Copyright (c) 2015 Dell Inc. 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
9 package org.opendaylight.netvirt.ipv6service;
10
11 import java.util.Collection;
12 import java.util.HashMap;
13 import java.util.Iterator;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class VirtualSubnet  {
21
22     private Uuid subnetUUID;
23     private Uuid tenantID;
24     private String name;
25     private IpAddress gatewayIp;
26     private IpPrefix subnetCidr;
27     private String ipVersion;
28     private String ipv6AddressMode;
29     private String ipv6RAMode;
30
31     // associated router
32     private VirtualRouter router;
33     // interface list
34     private HashMap<Uuid, VirtualPort> interfaces;
35
36
37     /**
38      * Logger instance.
39      */
40     static final Logger LOG = LoggerFactory.getLogger(VirtualSubnet.class);
41
42     void init() {
43         this.interfaces  = new HashMap<>();
44         this.router      = null;
45     }
46
47     public VirtualSubnet() {
48         init();
49     }
50
51     public VirtualSubnet setSubnetUUID(Uuid subnetUUID) {
52         this.subnetUUID = subnetUUID;
53         return this;
54     }
55
56     public Uuid getSubnetUUID() {
57         return subnetUUID;
58     }
59
60     public String getName() {
61         return name;
62     }
63
64     public VirtualSubnet setName(String name) {
65         this.name = name;
66         return this;
67     }
68
69     public Uuid getTenantID() {
70         return tenantID;
71     }
72
73     public VirtualSubnet setTenantID(Uuid tenantID) {
74         this.tenantID = tenantID;
75         return this;
76     }
77
78     public VirtualSubnet setGatewayIp(IpAddress gwIp) {
79         this.gatewayIp = gwIp;
80         return this;
81     }
82
83     public IpAddress getGatewayIp() {
84         return gatewayIp;
85     }
86
87     public VirtualSubnet setIPVersion(String ipVersion) {
88         this.ipVersion = ipVersion;
89         return this;
90     }
91
92     public String getIpVersion() {
93         return ipVersion;
94     }
95
96     public VirtualSubnet setSubnetCidr(IpPrefix subnetCidr) {
97         this.subnetCidr = subnetCidr;
98         return this;
99     }
100
101     public IpPrefix getSubnetCidr() {
102         return subnetCidr;
103     }
104
105     public VirtualSubnet setIpv6AddressMode(String ipv6AddressMode) {
106         this.ipv6AddressMode = ipv6AddressMode;
107         return this;
108     }
109
110     public String getIpv6AddressMode() {
111         return ipv6AddressMode;
112     }
113
114     public VirtualSubnet setIpv6RAMode(String ipv6RAMode) {
115         this.ipv6RAMode = ipv6RAMode;
116         return this;
117     }
118
119     public String getIpv6RAMode() {
120         return ipv6RAMode;
121     }
122
123     public void setRouter(VirtualRouter rtr) {
124         this.router = rtr;
125     }
126
127     public VirtualRouter getRouter() {
128         return router;
129     }
130
131     public void addInterface(VirtualPort intf) {
132         interfaces.put(intf.getIntfUUID(), intf);
133     }
134
135     public void removeInterface(VirtualPort intf) {
136         interfaces.remove(intf.getIntfUUID());
137     }
138
139     public void removeSelf() {
140         Collection<VirtualPort> intfs = interfaces.values();
141
142         Iterator itr = intfs.iterator();
143         while (itr.hasNext()) {
144             VirtualPort intf = (VirtualPort) itr.next();
145             if (intf != null) {
146                 intf.removeSubnetInfo(subnetUUID);
147             }
148         }
149
150         if (router != null) {
151             router.removeSubnet(this);
152         }
153         return;
154     }
155 }