blob: 801e78029ad45b125c07095128b245e26a5bf1d7 [file] [log] [blame]
Jonathan Hart062a2e82014-02-03 09:41:57 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08003/**
4 * Link Object stored in In-memory Topology.
5 *
6 * 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 {
Toshio Koide2f570c12014-02-06 16:55:32 -080010 protected Port srcPort;
11 protected Port dstPort;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080012
Toshio Koide2f570c12014-02-06 16:55:32 -080013 protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY;
14 protected Double capacity = DEFAULT_CAPACITY;
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080015
Toshio Koide2f570c12014-02-06 16:55:32 -080016 protected static final int DEFAULT_COST = 1;
17 protected int cost = DEFAULT_COST;
Jonathan Hart062a2e82014-02-03 09:41:57 -080018
Jonathan Hart891d0502014-02-10 10:04:08 -080019 /**
20 * Constructor for when a link is read from the database and the Ports
21 * already exist in the in-memory network graph.
22 * @param graph
23 * @param srcPort
24 * @param dstPort
25 */
Toshio Koide2f570c12014-02-06 16:55:32 -080026 public LinkImpl(NetworkGraph graph, Port srcPort, Port dstPort) {
Jonathan Hart062a2e82014-02-03 09:41:57 -080027 super(graph);
Toshio Koide2f570c12014-02-06 16:55:32 -080028 this.srcPort = srcPort;
29 this.dstPort = dstPort;
30 setToPorts();
31 }
32
33 protected void setToPorts() {
34 ((PortImpl)srcPort).setOutgoingLink(this);
Jonathan Hart4c263272014-02-13 17:41:05 -080035 ((PortImpl)dstPort).setIncomingLink(this);
Toshio Koide2f570c12014-02-06 16:55:32 -080036 }
Yuta HIGUCHI66c16812014-02-12 14:35:50 -080037
Toshio Koide2f570c12014-02-06 16:55:32 -080038 protected void unsetFromPorts() {
39 ((PortImpl)srcPort).setOutgoingLink(null);
Jonathan Hart4c263272014-02-13 17:41:05 -080040 ((PortImpl)dstPort).setIncomingLink(null);
Jonathan Hart062a2e82014-02-03 09:41:57 -080041 }
42
43 @Override
44 public Port getSourcePort() {
Toshio Koide2f570c12014-02-06 16:55:32 -080045 return srcPort;
Jonathan Hart062a2e82014-02-03 09:41:57 -080046 }
47
48 @Override
49 public Port getDestinationPort() {
Toshio Koide2f570c12014-02-06 16:55:32 -080050 return dstPort;
Jonathan Hart062a2e82014-02-03 09:41:57 -080051 }
52
53 @Override
54 public Switch getSourceSwitch() {
Toshio Koide2f570c12014-02-06 16:55:32 -080055 return srcPort.getSwitch();
Jonathan Hart062a2e82014-02-03 09:41:57 -080056 }
57
58 @Override
59 public Switch getDestinationSwitch() {
Toshio Koide2f570c12014-02-06 16:55:32 -080060 return dstPort.getSwitch();
Jonathan Hart062a2e82014-02-03 09:41:57 -080061 }
62
63 @Override
64 public long getLastSeenTime() {
65 // TODO Auto-generated method stub
66 return 0;
67 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080068
Jonathan Hart062a2e82014-02-03 09:41:57 -080069 @Override
70 public int getCost() {
71 return cost;
72 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080073
Jonathan Hart062a2e82014-02-03 09:41:57 -080074 public void setCost(int cost) {
75 this.cost = cost;
76 }
77
78 @Override
Toshio Koide0c9106d2014-02-19 15:26:38 -080079 public Double getCapacity() {
80 return capacity;
81 }
82
83 public void setCapacity(Double capacity) {
84 this.capacity = capacity;
85 }
86
87 @Deprecated
88 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080089 public Long getSourceSwitchDpid() {
Yuta HIGUCHI66c16812014-02-12 14:35:50 -080090 return srcPort.getSwitch().getDpid();
Jonathan Hart062a2e82014-02-03 09:41:57 -080091 }
92
Toshio Koide0c9106d2014-02-19 15:26:38 -080093 @Deprecated
Jonathan Hart062a2e82014-02-03 09:41:57 -080094 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -080095 public Long getSourcePortNumber() {
Yuta HIGUCHI66c16812014-02-12 14:35:50 -080096 return srcPort.getNumber();
Jonathan Hart062a2e82014-02-03 09:41:57 -080097 }
98
Toshio Koide0c9106d2014-02-19 15:26:38 -080099 @Deprecated
Toshio Koide2f570c12014-02-06 16:55:32 -0800100 @Override
101 public Long getDestinationSwitchDpid() {
Yuta HIGUCHI66c16812014-02-12 14:35:50 -0800102 return dstPort.getSwitch().getDpid();
Jonathan Hart062a2e82014-02-03 09:41:57 -0800103 }
104
Toshio Koide0c9106d2014-02-19 15:26:38 -0800105 @Deprecated
Jonathan Hart062a2e82014-02-03 09:41:57 -0800106 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -0800107 public Long getDestinationPortNumber() {
Yuta HIGUCHI66c16812014-02-12 14:35:50 -0800108 return dstPort.getNumber();
Jonathan Hart062a2e82014-02-03 09:41:57 -0800109 }
110
Toshio Koide2f570c12014-02-06 16:55:32 -0800111 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -0800112 public String toString() {
113 return String.format("%s --(cap:%f Mbps)--> %s",
114 getSourcePort().toString(),
115 getCapacity(),
116 getDestinationPort().toString());
Jonathan Hart062a2e82014-02-03 09:41:57 -0800117 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800118}