blob: 734717229b2acf1a3ecd5794d4bca0d652bc5ade [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Jonathan Hart062a2e82014-02-03 09:41:57 -08002
Jonathan Hart25bd53e2014-04-30 23:44:09 -07003import net.onrc.onos.core.util.SwitchPort;
4
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08005/**
6 * Link Object stored in In-memory Topology.
Ray Milkey269ffb92014-04-03 14:43:30 -07007 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08008 * TODO REMOVE following design memo: This object itself may hold the DBObject,
9 * but this Object itself will not issue any read/write to the DataStore.
10 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070011public class LinkImpl extends TopologyObject implements Link {
Jonathan Hart25bd53e2014-04-30 23:44:09 -070012 private SwitchPort srcPort;
13 private SwitchPort dstPort;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080014
Ray Milkey269ffb92014-04-03 14:43:30 -070015 protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
16 protected Double capacity = DEFAULT_CAPACITY;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080017
Ray Milkey269ffb92014-04-03 14:43:30 -070018 protected static final int DEFAULT_COST = 1;
19 protected int cost = DEFAULT_COST;
Jonathan Hart062a2e82014-02-03 09:41:57 -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() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070037 return topology.getSwitch(srcPort.dpid().value());
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() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070042 return topology.getPort(srcPort.dpid().value(), (long) srcPort.port().value());
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() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070047 return topology.getSwitch(dstPort.dpid().value());
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() {
Jonathan Harte37e4e22014-05-13 19:12:02 -070052 return topology.getPort(dstPort.dpid().value(), (long) dstPort.port().value());
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
62 public int getCost() {
63 return cost;
64 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 public void setCost(int cost) {
67 this.cost = cost;
68 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080069
Ray Milkey269ffb92014-04-03 14:43:30 -070070 @Override
71 public Double getCapacity() {
72 return capacity;
73 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080074
Ray Milkey269ffb92014-04-03 14:43:30 -070075 public void setCapacity(Double capacity) {
76 this.capacity = capacity;
77 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080078
Ray Milkey269ffb92014-04-03 14:43:30 -070079 @Override
80 public String toString() {
81 return String.format("%s --(cap:%f Mbps)--> %s",
82 getSrcPort().toString(),
83 getCapacity(),
84 getDstPort().toString());
85 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080086}