2 * Copyright (c) 2015 Dell Inc. and others. All rights reserved.
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
9 package org.opendaylight.netvirt.ipv6service;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class VirtualPort {
23 private Uuid intfUUID;
24 private Uuid networkID;
25 private String macAddress;
26 private Boolean routerIntfFlag;
28 private String deviceOwner;
30 private HashMap<Uuid, SubnetInfo> snetInfo;
32 // associated router if any
33 private VirtualRouter router = null;
35 // TODO:: Need Openflow port
40 static final Logger logger = LoggerFactory.getLogger(VirtualPort.class);
42 public VirtualPort() {
43 snetInfo = new HashMap<Uuid, SubnetInfo>();
46 public Uuid getIntfUUID() {
50 public VirtualPort setIntfUUID(Uuid intfUUID) {
51 this.intfUUID = intfUUID;
55 public Uuid getNetworkID() {
59 public VirtualPort setNetworkID(Uuid networkID) {
60 this.networkID = networkID;
64 public VirtualPort setSubnetInfo(Uuid snetID, IpAddress fixedIp) {
65 SubnetInfo subnetInfo = snetInfo.get(snetID);
66 if (subnetInfo == null) {
67 subnetInfo = new SubnetInfo(snetID, fixedIp);
68 snetInfo.put(snetID, subnetInfo);
70 subnetInfo.setIpAddr(fixedIp);
75 public void clearSubnetInfo() {
79 public void removeSubnetInfo(Uuid snetID) {
80 this.snetInfo.remove(snetID);
83 public void setSubnet(Uuid snetID, VirtualSubnet subnet) {
84 SubnetInfo subnetInfo = snetInfo.get(snetID);
85 if (subnetInfo == null) {
86 logger.info("Subnet {} not associated with the virtual port {}",
90 subnetInfo.setSubnet(subnet);
93 public List<VirtualSubnet> getSubnets() {
94 List<VirtualSubnet> subnetList = new ArrayList<>();
95 for (SubnetInfo subnetInfo : snetInfo.values()) {
96 if (subnetInfo.getSubnet() != null) {
97 subnetList.add(subnetInfo.getSubnet());
103 public List<IpAddress> getIpAddresses() {
104 List<IpAddress> ipAddrList = new ArrayList<>();
105 for (SubnetInfo subnetInfo : snetInfo.values()) {
106 ipAddrList.add(subnetInfo.getIpAddr());
111 public String getMacAddress() {
115 public VirtualPort setMacAddress(String macAddress) {
116 this.macAddress = macAddress;
120 public Boolean getRouterIntfFlag() {
121 return routerIntfFlag;
124 public VirtualPort setRouterIntfFlag(Boolean routerIntfFlag) {
125 this.routerIntfFlag = routerIntfFlag;
129 public void setRouter(VirtualRouter rtr) {
133 public VirtualRouter getRouter() {
137 public VirtualPort setDeviceOwner(String deviceOwner) {
138 this.deviceOwner = deviceOwner;
142 public String getDeviceOwner() {
146 public VirtualPort setDpId(String dpId) {
151 public String getDpId() {
155 public void setOfPort(Long ofPort) {
156 this.ofPort = ofPort;
159 public Long getOfPort() {
163 public void removeSelf() {
164 if (routerIntfFlag == true) {
165 if (router != null) {
166 router.removeInterface(this);
170 for (SubnetInfo subnetInfo: snetInfo.values()) {
171 if (subnetInfo.getSubnet() != null) {
172 subnetInfo.getSubnet().removeInterface(this);
178 public String toString() {
179 return "VirtualPort[IntfUUid=" + intfUUID + " subnetInfo="
180 + snetInfo + " NetworkId=" + networkID + " mac=" + macAddress + " ofPort="
181 + ofPort + " routerFlag=" + routerIntfFlag + " dpId=" + dpId + "]";
184 private class SubnetInfo {
185 private Uuid subnetID;
186 private IpAddress ipAddr;
188 private VirtualSubnet subnet = null;
190 SubnetInfo(Uuid subnetId, IpAddress ipAddr) {
191 this.subnetID = subnetId;
192 this.ipAddr = ipAddr;
195 public Uuid getSubnetID() {
199 public IpAddress getIpAddr() {
203 public void setIpAddr(IpAddress ipAddr) {
204 this.ipAddr = ipAddr;
207 public VirtualSubnet getSubnet() {
211 public void setSubnet(VirtualSubnet subnet) {
212 this.subnet = subnet;
216 public String toString() {
217 return "subnetInfot[subnetId=" + subnetID + " ipAddr=" + ipAddr + " ]";