blob: 412113cae8570cbbe5ad006dd0880792d145f31e [file] [log] [blame]
Jonathan Hart062a2e82014-02-03 09:41:57 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
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
Toshio Koide2f570c12014-02-06 16:55:32 -080033 public Long getNumber() {
Jonathan Hart062a2e82014-02-03 09:41:57 -080034 return number;
35 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080036
Jonathan Hart891d0502014-02-10 10:04:08 -080037 @Override
38 public String getDescription() {
39 return description;
40 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080041
Jonathan Hart891d0502014-02-10 10:04:08 -080042 public void setDescription(String description) {
43 this.description = description;
44 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080045
Jonathan Hart062a2e82014-02-03 09:41:57 -080046 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080047 public Long getHardwareAddress() {
Jonathan Hart062a2e82014-02-03 09:41:57 -080048 // TODO Auto-generated method stub
Toshio Koide2f570c12014-02-06 16:55:32 -080049 return 0L;
Jonathan Hart062a2e82014-02-03 09:41:57 -080050 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080051
Jonathan Hart062a2e82014-02-03 09:41:57 -080052 @Override
53 public Switch getSwitch() {
54 return sw;
55 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080056
Toshio Koide2f570c12014-02-06 16:55:32 -080057 @Override
58 public Link getOutgoingLink() {
59 return outgoingLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -080060 }
61
62 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080063 public Link getIncomingLink() {
64 return incomingLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -080065 }
66
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080067 @Override
68 public Iterable<Device> getDevices() {
69 return Collections.unmodifiableSet(this.devices);
70 }
71
Toshio Koide2f570c12014-02-06 16:55:32 -080072 public void setOutgoingLink(Link link) {
73 outgoingLink = link;
74 }
75
76 public void setIncomingLink(Link link) {
77 incomingLink = link;
78 }
79
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080080 /**
81 *
82 * @param d
83 * @return true if successfully added
84 */
85 public boolean addDevice(Device d) {
86 return this.devices.add(d);
87 }
88
89 /**
90 *
91 * @param d
92 * @return true if device existed and was removed
93 */
94 public boolean removeDevice(Device d) {
95 return this.devices.remove(d);
96 }
97
Toshio Koide2f570c12014-02-06 16:55:32 -080098 @Override
99 public String toString() {
100 return String.format("%d:%d",
101 getSwitch().getDpid(),
102 getNumber());
103 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800104}