blob: 5542e6401a1a309119a5ec2751f10e49143fc8bd [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 protected static final int DEFAULT_COST = 1;
22 protected int cost = DEFAULT_COST;
Jonathan Hart062a2e82014-02-03 09:41:57 -080023
Ray Milkey269ffb92014-04-03 14:43:30 -070024 /**
25 * Constructor for when a link is read from the database and the Ports
Jonathan Harte37e4e22014-05-13 19:12:02 -070026 * already exist in the in-memory topology.
Ray Milkey269ffb92014-04-03 14:43:30 -070027 *
Jonathan Harte37e4e22014-05-13 19:12:02 -070028 * @param topology
Ray Milkey269ffb92014-04-03 14:43:30 -070029 * @param srcPort
30 * @param dstPort
31 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070032 public LinkImpl(Topology topology, Port srcPort, Port dstPort) {
33 super(topology);
Jonathan Hart25bd53e2014-04-30 23:44:09 -070034 this.srcPort = srcPort.asSwitchPort();
35 this.dstPort = dstPort.asSwitchPort();
Ray Milkey269ffb92014-04-03 14:43:30 -070036 }
Toshio Koide2f570c12014-02-06 16:55:32 -080037
Ray Milkey269ffb92014-04-03 14:43:30 -070038 @Override
39 public Switch getSrcSwitch() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070040 return topology.getSwitch(srcPort.dpid().value());
Ray Milkey269ffb92014-04-03 14:43:30 -070041 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080042
Ray Milkey269ffb92014-04-03 14:43:30 -070043 @Override
44 public Port getSrcPort() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070045 return topology.getPort(srcPort.dpid().value(), (long) srcPort.port().value());
Ray Milkey269ffb92014-04-03 14:43:30 -070046 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080047
Ray Milkey269ffb92014-04-03 14:43:30 -070048 @Override
49 public Switch getDstSwitch() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070050 return topology.getSwitch(dstPort.dpid().value());
Ray Milkey269ffb92014-04-03 14:43:30 -070051 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080052
Ray Milkey269ffb92014-04-03 14:43:30 -070053 @Override
54 public Port getDstPort() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070055 return topology.getPort(dstPort.dpid().value(), (long) dstPort.port().value());
Ray Milkey269ffb92014-04-03 14:43:30 -070056 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080057
Ray Milkey269ffb92014-04-03 14:43:30 -070058 @Override
59 public long getLastSeenTime() {
60 // TODO Auto-generated method stub
61 return 0;
62 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080063
Ray Milkey269ffb92014-04-03 14:43:30 -070064 @Override
65 public int getCost() {
66 return cost;
67 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080068
Ray Milkey269ffb92014-04-03 14:43:30 -070069 public void setCost(int cost) {
70 this.cost = cost;
71 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080072
Ray Milkey269ffb92014-04-03 14:43:30 -070073 @Override
74 public Double getCapacity() {
75 return capacity;
76 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080077
Ray Milkey269ffb92014-04-03 14:43:30 -070078 public void setCapacity(Double capacity) {
79 this.capacity = capacity;
80 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080081
Ray Milkey269ffb92014-04-03 14:43:30 -070082 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070083 public String getStringAttribute(String attr) {
84 throw new UnsupportedOperationException("Not implemented yet");
85 }
86
87 @Override
88 @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
89 justification = "getStringAttribute might return null once implemented")
90 public String getStringAttribute(String attr, String def) {
91 final String v = getStringAttribute(attr);
92 if (v == null) {
93 return def;
94 } else {
95 return v;
96 }
97 }
98
99 @Override
100 public Map<String, String> getAllStringAttributes() {
101 throw new UnsupportedOperationException("Not implemented yet");
102 }
103
104 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700105 public String toString() {
106 return String.format("%s --(cap:%f Mbps)--> %s",
107 getSrcPort().toString(),
108 getCapacity(),
109 getDstPort().toString());
110 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800111}