Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 3 | /** |
| 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 Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 9 | public class LinkImpl extends NetworkGraphObject implements Link { |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 10 | protected Port srcPort; |
| 11 | protected Port dstPort; |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 12 | |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 13 | protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY; |
| 14 | protected Double capacity = DEFAULT_CAPACITY; |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 15 | |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 16 | protected static final int DEFAULT_COST = 1; |
| 17 | protected int cost = DEFAULT_COST; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 18 | |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 19 | public LinkImpl(NetworkGraph graph, Port srcPort, Port dstPort) { |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 20 | super(graph); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 21 | this.srcPort = srcPort; |
| 22 | this.dstPort = dstPort; |
| 23 | setToPorts(); |
| 24 | } |
| 25 | |
| 26 | protected void setToPorts() { |
| 27 | ((PortImpl)srcPort).setOutgoingLink(this); |
| 28 | ((PortImpl)srcPort).setIncomingLink(this); |
| 29 | } |
| 30 | |
| 31 | protected void unsetFromPorts() { |
| 32 | ((PortImpl)srcPort).setOutgoingLink(null); |
| 33 | ((PortImpl)srcPort).setIncomingLink(null); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public Port getSourcePort() { |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 38 | return srcPort; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public Port getDestinationPort() { |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 43 | return dstPort; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public Switch getSourceSwitch() { |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 48 | return srcPort.getSwitch(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Switch getDestinationSwitch() { |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 53 | return dstPort.getSwitch(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public long getLastSeenTime() { |
| 58 | // TODO Auto-generated method stub |
| 59 | return 0; |
| 60 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 61 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 62 | @Override |
| 63 | public int getCost() { |
| 64 | return cost; |
| 65 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 66 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 67 | public void setCost(int cost) { |
| 68 | this.cost = cost; |
| 69 | } |
| 70 | |
| 71 | @Override |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 72 | public Long getSourceSwitchDpid() { |
| 73 | return srcPort.getSwitch().getDpid(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 77 | public Long getSourcePortNumber() { |
Yuta HIGUCHI | e1d9276 | 2014-02-06 12:05:52 -0800 | [diff] [blame] | 78 | return srcPort.getNumber(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 81 | @Override |
| 82 | public Long getDestinationSwitchDpid() { |
| 83 | return dstPort.getSwitch().getDpid(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 87 | public Long getDestinationPortNumber() { |
Yuta HIGUCHI | e1d9276 | 2014-02-06 12:05:52 -0800 | [diff] [blame] | 88 | return dstPort.getNumber(); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 91 | @Override |
| 92 | public Double getCapacity() { |
| 93 | return capacity; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public String toString() { |
| 98 | return String.format("%s --(cap:%f Mbps)--> %s", |
| 99 | getSourcePort().toString(), |
| 100 | getCapacity(), |
| 101 | getDestinationPort().toString()); |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 104 | public void setCapacity(Double capacity) { |
| 105 | this.capacity = capacity; |
| 106 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 107 | } |