blob: 933276446589a772e28a6896516ef004ade107a8 [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 HIGUCHIdb1b8302014-06-26 10:50:39 -07003import java.util.Map;
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -07004import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -07005import net.onrc.onos.core.util.Dpid;
6import net.onrc.onos.core.util.PortNumber;
Jonathan Hart25bd53e2014-04-30 23:44:09 -07007import net.onrc.onos.core.util.SwitchPort;
8
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08009/**
10 * Port Object stored in In-memory Topology.
Ray Milkey269ffb92014-04-03 14:43:30 -070011 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080012 * TODO REMOVE following design memo: This object itself may hold the DBObject,
13 * but this Object itself will not issue any read/write to the DataStore.
14 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070015public class PortImpl extends TopologyObject implements Port {
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080016
Ray Milkey269ffb92014-04-03 14:43:30 -070017 private Switch sw;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080018
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070019 private PortNumber number;
Ray Milkey269ffb92014-04-03 14:43:30 -070020 private String description;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080021
Jonathan Hart25bd53e2014-04-30 23:44:09 -070022 private final SwitchPort switchPort;
23
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070024 public PortImpl(Topology topology, Switch parentSwitch, PortNumber number) {
Jonathan Harte37e4e22014-05-13 19:12:02 -070025 super(topology);
Ray Milkey269ffb92014-04-03 14:43:30 -070026 this.sw = parentSwitch;
27 this.number = number;
Jonathan Hart25bd53e2014-04-30 23:44:09 -070028
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070029 switchPort = new SwitchPort(parentSwitch.getDpid(),
30 number);
31 }
32
33 public PortImpl(Topology topology, Switch parentSwitch, Long number) {
34 this(topology, parentSwitch, new PortNumber(number.shortValue()));
Ray Milkey269ffb92014-04-03 14:43:30 -070035 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080036
Ray Milkey269ffb92014-04-03 14:43:30 -070037 @Override
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070038 public Dpid getDpid() {
Ray Milkey269ffb92014-04-03 14:43:30 -070039 return sw.getDpid();
40 }
Yuta HIGUCHIea516d62014-02-13 15:59:32 -080041
Ray Milkey269ffb92014-04-03 14:43:30 -070042 @Override
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070043 public PortNumber getNumber() {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 return number;
45 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080046
Ray Milkey269ffb92014-04-03 14:43:30 -070047 @Override
Jonathan Hart25bd53e2014-04-30 23:44:09 -070048 public SwitchPort asSwitchPort() {
49 return switchPort;
50 }
51
52 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070053 public String getDescription() {
54 return description;
55 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080056
Ray Milkey269ffb92014-04-03 14:43:30 -070057 public void setDescription(String description) {
58 this.description = description;
59 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080060
Ray Milkey269ffb92014-04-03 14:43:30 -070061 @Override
62 public Long getHardwareAddress() {
63 // TODO Auto-generated method stub
64 return 0L;
65 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080066
Ray Milkey269ffb92014-04-03 14:43:30 -070067 @Override
68 public Switch getSwitch() {
69 return sw;
70 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080071
Ray Milkey269ffb92014-04-03 14:43:30 -070072 @Override
73 public Link getOutgoingLink() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070074 return topology.getOutgoingLink(switchPort.dpid(),
75 switchPort.port());
Ray Milkey269ffb92014-04-03 14:43:30 -070076 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080077
Ray Milkey269ffb92014-04-03 14:43:30 -070078 @Override
79 public Link getIncomingLink() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070080 return topology.getIncomingLink(switchPort.dpid(),
81 switchPort.port());
Ray Milkey269ffb92014-04-03 14:43:30 -070082 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080083
Ray Milkey269ffb92014-04-03 14:43:30 -070084 @Override
85 public Iterable<Device> getDevices() {
Yuta HIGUCHIfa742842014-07-03 22:35:13 -070086 return topology.getDevices(this.asSwitchPort());
Ray Milkey269ffb92014-04-03 14:43:30 -070087 }
Yuta HIGUCHIcd922f42014-02-11 18:59:11 -080088
Ray Milkey269ffb92014-04-03 14:43:30 -070089 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070090 public String getStringAttribute(String attr) {
91 throw new UnsupportedOperationException("Not implemented yet");
92 }
93
94 @Override
95 @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
96 justification = "getStringAttribute might return null once implemented")
97 public String getStringAttribute(String attr, String def) {
98 final String v = getStringAttribute(attr);
99 if (v == null) {
100 return def;
101 } else {
102 return v;
103 }
104 }
105
106 @Override
107 public Map<String, String> getAllStringAttributes() {
108 throw new UnsupportedOperationException("Not implemented yet");
109 }
110
111 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700112 public String toString() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -0700113 return String.format("%s:%s",
Ray Milkey269ffb92014-04-03 14:43:30 -0700114 getSwitch().getDpid(),
115 getNumber());
116 }
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -0700117
118
119 /**
120 * Returns the type of topology object.
121 *
122 * @return the type of the topology object
123 */
124 @Override
125 public String getType() {
126 throw new UnsupportedOperationException("Not implemented yet");
127 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800128}