blob: 32646d0cf24daeaacb2639516a6034d60c907c89 [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.
Ray Milkey269ffb92014-04-03 14:43:30 -07009 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080010 * 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
Ray Milkey269ffb92014-04-03 14:43:30 -070015 private Switch sw;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080016
Ray Milkey269ffb92014-04-03 14:43:30 -070017 private Long number;
18 private String description;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080019
Ray Milkey269ffb92014-04-03 14:43:30 -070020 protected Link outgoingLink;
21 protected Link incomingLink;
22 // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
23 protected Set<Device> devices;
Jonathan Hart062a2e82014-02-03 09:41:57 -080024
Ray Milkey269ffb92014-04-03 14:43:30 -070025 public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) {
26 super(graph);
27 this.sw = parentSwitch;
28 this.number = number;
29 this.devices = new HashSet<>();
30 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080031
Ray Milkey269ffb92014-04-03 14:43:30 -070032 @Override
33 public Long getDpid() {
34 return sw.getDpid();
35 }
Yuta HIGUCHIea516d62014-02-13 15:59:32 -080036
Ray Milkey269ffb92014-04-03 14:43:30 -070037 @Override
38 public Long getNumber() {
39 return number;
40 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080041
Ray Milkey269ffb92014-04-03 14:43:30 -070042 @Override
43 public String getDescription() {
44 return description;
45 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080046
Ray Milkey269ffb92014-04-03 14:43:30 -070047 public void setDescription(String description) {
48 this.description = description;
49 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080050
Ray Milkey269ffb92014-04-03 14:43:30 -070051 @Override
52 public Long getHardwareAddress() {
53 // TODO Auto-generated method stub
54 return 0L;
55 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080056
Ray Milkey269ffb92014-04-03 14:43:30 -070057 @Override
58 public Switch getSwitch() {
59 return sw;
60 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080061
Ray Milkey269ffb92014-04-03 14:43:30 -070062 @Override
63 public Link getOutgoingLink() {
64 return outgoingLink;
65 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080066
Ray Milkey269ffb92014-04-03 14:43:30 -070067 @Override
68 public Link getIncomingLink() {
69 return incomingLink;
70 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080071
Ray Milkey269ffb92014-04-03 14:43:30 -070072 @Override
73 public Iterable<Device> getDevices() {
74 return Collections.unmodifiableSet(this.devices);
75 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080076
Ray Milkey269ffb92014-04-03 14:43:30 -070077 public void setOutgoingLink(Link link) {
78 outgoingLink = link;
79 }
Toshio Koide2f570c12014-02-06 16:55:32 -080080
Ray Milkey269ffb92014-04-03 14:43:30 -070081 public void setIncomingLink(Link link) {
82 incomingLink = link;
83 }
Toshio Koide2f570c12014-02-06 16:55:32 -080084
Ray Milkey269ffb92014-04-03 14:43:30 -070085 /**
86 * @param d
87 * @return true if successfully added
88 */
89 public boolean addDevice(Device d) {
90 return this.devices.add(d);
91 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080092
Ray Milkey269ffb92014-04-03 14:43:30 -070093 /**
94 * @param d
95 * @return true if device existed and was removed
96 */
97 public boolean removeDevice(Device d) {
98 return this.devices.remove(d);
99 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800100
Ray Milkey269ffb92014-04-03 14:43:30 -0700101 public void removeAllDevice() {
102 this.devices.clear();
103 }
Yuta HIGUCHIcd922f42014-02-11 18:59:11 -0800104
Ray Milkey269ffb92014-04-03 14:43:30 -0700105 @Override
106 public String toString() {
107 return String.format("%d:%d",
108 getSwitch().getDpid(),
109 getNumber());
110 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800111}