blob: cd7d82b7b00e54e397e33123e6baa41ff4803ad6 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Jonathan Hart062a2e82014-02-03 09:41:57 -08002
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -08003import java.util.Collections;
4import java.util.HashSet;
5import java.util.Set;
6
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08007/**
8 * Port Object stored in In-memory Topology.
9 *
10 * TODO REMOVE following design memo: This object itself may hold the DBObject,
11 * but this Object itself will not issue any read/write to the DataStore.
12 */
Jonathan Hart062a2e82014-02-03 09:41:57 -080013public class PortImpl extends NetworkGraphObject implements Port {
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080014
Jonathan Hart062a2e82014-02-03 09:41:57 -080015 private Switch sw;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080016
Toshio Koide2f570c12014-02-06 16:55:32 -080017 private Long number;
Jonathan Hart891d0502014-02-10 10:04:08 -080018 private String description;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080019
Toshio Koide2f570c12014-02-06 16:55:32 -080020 protected Link outgoingLink;
21 protected Link incomingLink;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080022 // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080023 protected Set<Device> devices;
Jonathan Hart062a2e82014-02-03 09:41:57 -080024
Toshio Koide2f570c12014-02-06 16:55:32 -080025 public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) {
Jonathan Hart062a2e82014-02-03 09:41:57 -080026 super(graph);
Toshio Koide2f570c12014-02-06 16:55:32 -080027 this.sw = parentSwitch;
28 this.number = number;
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080029 this.devices = new HashSet<>();
Jonathan Hart062a2e82014-02-03 09:41:57 -080030 }
31
32 @Override
Yuta HIGUCHIea516d62014-02-13 15:59:32 -080033 public Long getDpid() {
34 return sw.getDpid();
35 }
36
37 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080038 public Long getNumber() {
Jonathan Hart062a2e82014-02-03 09:41:57 -080039 return number;
40 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080041
Jonathan Hart891d0502014-02-10 10:04:08 -080042 @Override
43 public String getDescription() {
44 return description;
45 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080046
Jonathan Hart891d0502014-02-10 10:04:08 -080047 public void setDescription(String description) {
48 this.description = description;
49 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080050
Jonathan Hart062a2e82014-02-03 09:41:57 -080051 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080052 public Long getHardwareAddress() {
Jonathan Hart062a2e82014-02-03 09:41:57 -080053 // TODO Auto-generated method stub
Toshio Koide2f570c12014-02-06 16:55:32 -080054 return 0L;
Jonathan Hart062a2e82014-02-03 09:41:57 -080055 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080056
Jonathan Hart062a2e82014-02-03 09:41:57 -080057 @Override
58 public Switch getSwitch() {
59 return sw;
60 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080061
Toshio Koide2f570c12014-02-06 16:55:32 -080062 @Override
63 public Link getOutgoingLink() {
64 return outgoingLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -080065 }
66
67 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080068 public Link getIncomingLink() {
69 return incomingLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -080070 }
71
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080072 @Override
73 public Iterable<Device> getDevices() {
74 return Collections.unmodifiableSet(this.devices);
75 }
76
Toshio Koide2f570c12014-02-06 16:55:32 -080077 public void setOutgoingLink(Link link) {
78 outgoingLink = link;
79 }
80
81 public void setIncomingLink(Link link) {
82 incomingLink = link;
83 }
84
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080085 /**
86 *
87 * @param d
88 * @return true if successfully added
89 */
90 public boolean addDevice(Device d) {
91 return this.devices.add(d);
92 }
93
94 /**
95 *
96 * @param d
97 * @return true if device existed and was removed
98 */
99 public boolean removeDevice(Device d) {
100 return this.devices.remove(d);
101 }
102
Yuta HIGUCHIcd922f42014-02-11 18:59:11 -0800103 public void removeAllDevice() {
104 this.devices.clear();
105 }
106
Toshio Koide2f570c12014-02-06 16:55:32 -0800107 @Override
108 public String toString() {
109 return String.format("%d:%d",
110 getSwitch().getDpid(),
111 getNumber());
112 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800113}