blob: 4333e38a567e6f80f293414b18b36f7e3bde02c1 [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 HIGUCHI181d34d2014-02-05 15:05:46 -08003/**
4 * Link Object stored in In-memory Topology.
Ray Milkey269ffb92014-04-03 14:43:30 -07005 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08006 * TODO REMOVE following design memo: This object itself may hold the DBObject,
7 * but this Object itself will not issue any read/write to the DataStore.
8 */
Jonathan Hart062a2e82014-02-03 09:41:57 -08009public class LinkImpl extends NetworkGraphObject implements Link {
Ray Milkey269ffb92014-04-03 14:43:30 -070010 protected Port srcPort;
11 protected Port dstPort;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080012
Ray Milkey269ffb92014-04-03 14:43:30 -070013 protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
14 protected Double capacity = DEFAULT_CAPACITY;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080015
Ray Milkey269ffb92014-04-03 14:43:30 -070016 protected static final int DEFAULT_COST = 1;
17 protected int cost = DEFAULT_COST;
Jonathan Hart062a2e82014-02-03 09:41:57 -080018
Ray Milkey269ffb92014-04-03 14:43:30 -070019 /**
20 * Constructor for when a link is read from the database and the Ports
21 * already exist in the in-memory network graph.
22 *
23 * @param graph
24 * @param srcPort
25 * @param dstPort
26 */
27 public LinkImpl(NetworkGraph graph, Port srcPort, Port dstPort) {
28 super(graph);
29 this.srcPort = srcPort;
30 this.dstPort = dstPort;
31 setToPorts();
32 }
Toshio Koide2f570c12014-02-06 16:55:32 -080033
Ray Milkey269ffb92014-04-03 14:43:30 -070034 @Override
35 public Switch getSrcSwitch() {
36 return srcPort.getSwitch();
37 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080038
Ray Milkey269ffb92014-04-03 14:43:30 -070039 @Override
40 public Port getSrcPort() {
41 return srcPort;
42 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080043
Ray Milkey269ffb92014-04-03 14:43:30 -070044 @Override
45 public Switch getDstSwitch() {
46 return dstPort.getSwitch();
47 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080048
Ray Milkey269ffb92014-04-03 14:43:30 -070049 @Override
50 public Port getDstPort() {
51 return dstPort;
52 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080053
Ray Milkey269ffb92014-04-03 14:43:30 -070054 protected void setToPorts() {
55 ((PortImpl) srcPort).setOutgoingLink(this);
56 ((PortImpl) dstPort).setIncomingLink(this);
57 }
Yuta HIGUCHI66c16812014-02-12 14:35:50 -080058
Ray Milkey269ffb92014-04-03 14:43:30 -070059 protected void unsetFromPorts() {
60 ((PortImpl) srcPort).setOutgoingLink(null);
61 ((PortImpl) dstPort).setIncomingLink(null);
62 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080063
Ray Milkey269ffb92014-04-03 14:43:30 -070064 @Override
65 public long getLastSeenTime() {
66 // TODO Auto-generated method stub
67 return 0;
68 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080069
Ray Milkey269ffb92014-04-03 14:43:30 -070070 @Override
71 public int getCost() {
72 return cost;
73 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080074
Ray Milkey269ffb92014-04-03 14:43:30 -070075 public void setCost(int cost) {
76 this.cost = cost;
77 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080078
Ray Milkey269ffb92014-04-03 14:43:30 -070079 @Override
80 public Double getCapacity() {
81 return capacity;
82 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080083
Ray Milkey269ffb92014-04-03 14:43:30 -070084 public void setCapacity(Double capacity) {
85 this.capacity = capacity;
86 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080087
Ray Milkey269ffb92014-04-03 14:43:30 -070088 @Override
89 public String toString() {
90 return String.format("%s --(cap:%f Mbps)--> %s",
91 getSrcPort().toString(),
92 getCapacity(),
93 getDstPort().toString());
94 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080095}