blob: 6f860d03ce8fb8e67578defa38d8641c0dde71b9 [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;
Jonathan Hart891d0502014-02-10 10:04:08 -080016
Toshio Koide2f570c12014-02-06 16:55:32 -080017 private Long number;
Jonathan Hart891d0502014-02-10 10:04:08 -080018 private String description;
19
Toshio Koide2f570c12014-02-06 16:55:32 -080020 protected Link outgoingLink;
21 protected Link incomingLink;
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080022 protected Set<Device> devices;
Jonathan Hart062a2e82014-02-03 09:41:57 -080023
Toshio Koide2f570c12014-02-06 16:55:32 -080024 public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) {
Jonathan Hart062a2e82014-02-03 09:41:57 -080025 super(graph);
Toshio Koide2f570c12014-02-06 16:55:32 -080026 this.sw = parentSwitch;
27 this.number = number;
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080028 this.devices = new HashSet<>();
Jonathan Hart062a2e82014-02-03 09:41:57 -080029 }
30
31 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080032 public Long getNumber() {
Jonathan Hart062a2e82014-02-03 09:41:57 -080033 return number;
34 }
Jonathan Hart891d0502014-02-10 10:04:08 -080035
36 @Override
37 public String getDescription() {
38 return description;
39 }
40
41 public void setDescription(String description) {
42 this.description = description;
43 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080044
Jonathan Hart062a2e82014-02-03 09:41:57 -080045 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080046 public Long getHardwareAddress() {
Jonathan Hart062a2e82014-02-03 09:41:57 -080047 // TODO Auto-generated method stub
Toshio Koide2f570c12014-02-06 16:55:32 -080048 return 0L;
Jonathan Hart062a2e82014-02-03 09:41:57 -080049 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080050
Jonathan Hart062a2e82014-02-03 09:41:57 -080051 @Override
52 public Switch getSwitch() {
53 return sw;
54 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080055
Toshio Koide2f570c12014-02-06 16:55:32 -080056 @Override
57 public Link getOutgoingLink() {
58 return outgoingLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -080059 }
60
61 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080062 public Link getIncomingLink() {
63 return incomingLink;
Jonathan Hart062a2e82014-02-03 09:41:57 -080064 }
65
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080066 @Override
67 public Iterable<Device> getDevices() {
68 return Collections.unmodifiableSet(this.devices);
69 }
70
Toshio Koide2f570c12014-02-06 16:55:32 -080071 public void setOutgoingLink(Link link) {
72 outgoingLink = link;
73 }
74
75 public void setIncomingLink(Link link) {
76 incomingLink = link;
77 }
78
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080079 /**
80 *
81 * @param d
82 * @return true if successfully added
83 */
84 public boolean addDevice(Device d) {
85 return this.devices.add(d);
86 }
87
88 /**
89 *
90 * @param d
91 * @return true if device existed and was removed
92 */
93 public boolean removeDevice(Device d) {
94 return this.devices.remove(d);
95 }
96
Toshio Koide2f570c12014-02-06 16:55:32 -080097 @Override
98 public String toString() {
99 return String.format("%d:%d",
100 getSwitch().getDpid(),
101 getNumber());
102 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800103}