blob: d0276d11efa26b2a8195c8415de5cc19ec86a368 [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;
4
5import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Jonathan Hart25bd53e2014-04-30 23:44:09 -07006import net.onrc.onos.core.util.SwitchPort;
7
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08008/**
9 * Link Object stored in In-memory Topology.
Ray Milkey269ffb92014-04-03 14:43:30 -070010 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080011 * TODO REMOVE following design memo: This object itself may hold the DBObject,
12 * but this Object itself will not issue any read/write to the DataStore.
13 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070014public class LinkImpl extends TopologyObject implements Link {
Jonathan Hart25bd53e2014-04-30 23:44:09 -070015 private SwitchPort srcPort;
16 private SwitchPort dstPort;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080017
Ray Milkey269ffb92014-04-03 14:43:30 -070018 protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
19 protected Double capacity = DEFAULT_CAPACITY;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080020
Ray Milkey269ffb92014-04-03 14:43:30 -070021 /**
22 * Constructor for when a link is read from the database and the Ports
Jonathan Harte37e4e22014-05-13 19:12:02 -070023 * already exist in the in-memory topology.
Ray Milkey269ffb92014-04-03 14:43:30 -070024 *
Jonathan Harte37e4e22014-05-13 19:12:02 -070025 * @param topology
Ray Milkey269ffb92014-04-03 14:43:30 -070026 * @param srcPort
27 * @param dstPort
28 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070029 public LinkImpl(Topology topology, Port srcPort, Port dstPort) {
30 super(topology);
Jonathan Hart25bd53e2014-04-30 23:44:09 -070031 this.srcPort = srcPort.asSwitchPort();
32 this.dstPort = dstPort.asSwitchPort();
Ray Milkey269ffb92014-04-03 14:43:30 -070033 }
Toshio Koide2f570c12014-02-06 16:55:32 -080034
Ray Milkey269ffb92014-04-03 14:43:30 -070035 @Override
36 public Switch getSrcSwitch() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070037 return topology.getSwitch(srcPort.dpid());
Ray Milkey269ffb92014-04-03 14:43:30 -070038 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080039
Ray Milkey269ffb92014-04-03 14:43:30 -070040 @Override
41 public Port getSrcPort() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070042 return topology.getPort(srcPort.dpid(), srcPort.port());
Ray Milkey269ffb92014-04-03 14:43:30 -070043 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080044
Ray Milkey269ffb92014-04-03 14:43:30 -070045 @Override
46 public Switch getDstSwitch() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070047 return topology.getSwitch(dstPort.dpid());
Ray Milkey269ffb92014-04-03 14:43:30 -070048 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080049
Ray Milkey269ffb92014-04-03 14:43:30 -070050 @Override
51 public Port getDstPort() {
Yuta HIGUCHI8f3dfa32014-06-25 00:14:25 -070052 return topology.getPort(dstPort.dpid(), dstPort.port());
Ray Milkey269ffb92014-04-03 14:43:30 -070053 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 @Override
56 public long getLastSeenTime() {
57 // TODO Auto-generated method stub
58 return 0;
59 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080060
Ray Milkey269ffb92014-04-03 14:43:30 -070061 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070062 public Double getCapacity() {
63 return capacity;
64 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 public void setCapacity(Double capacity) {
67 this.capacity = capacity;
68 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080069
Ray Milkey269ffb92014-04-03 14:43:30 -070070 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070071 public String getStringAttribute(String attr) {
72 throw new UnsupportedOperationException("Not implemented yet");
73 }
74
75 @Override
76 @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
77 justification = "getStringAttribute might return null once implemented")
78 public String getStringAttribute(String attr, String def) {
79 final String v = getStringAttribute(attr);
80 if (v == null) {
81 return def;
82 } else {
83 return v;
84 }
85 }
86
87 @Override
88 public Map<String, String> getAllStringAttributes() {
89 throw new UnsupportedOperationException("Not implemented yet");
90 }
91
92 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070093 public String toString() {
94 return String.format("%s --(cap:%f Mbps)--> %s",
95 getSrcPort().toString(),
96 getCapacity(),
97 getDstPort().toString());
98 }
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070099
100
101 /**
102 * Returns the type of topology object.
103 *
104 * @return the type of the topology object
105 */
106 @Override
107 public String getType() {
108 throw new UnsupportedOperationException("Not implemented yet");
109 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800110}