Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 2 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 3 | /** |
| 4 | * Link Object stored in In-memory Topology. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 5 | * <p/> |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 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 { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 10 | protected Port srcPort; |
| 11 | protected Port dstPort; |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 12 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [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 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [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 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | /** |
| 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 Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 33 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | @Override |
| 35 | public Switch getSrcSwitch() { |
| 36 | return srcPort.getSwitch(); |
| 37 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 38 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public Port getSrcPort() { |
| 41 | return srcPort; |
| 42 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 43 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | @Override |
| 45 | public Switch getDstSwitch() { |
| 46 | return dstPort.getSwitch(); |
| 47 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 48 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 49 | @Override |
| 50 | public Port getDstPort() { |
| 51 | return dstPort; |
| 52 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 53 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 54 | protected void setToPorts() { |
| 55 | ((PortImpl) srcPort).setOutgoingLink(this); |
| 56 | ((PortImpl) dstPort).setIncomingLink(this); |
| 57 | } |
Yuta HIGUCHI | 66c1681 | 2014-02-12 14:35:50 -0800 | [diff] [blame] | 58 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | protected void unsetFromPorts() { |
| 60 | ((PortImpl) srcPort).setOutgoingLink(null); |
| 61 | ((PortImpl) dstPort).setIncomingLink(null); |
| 62 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 63 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | @Override |
| 65 | public long getLastSeenTime() { |
| 66 | // TODO Auto-generated method stub |
| 67 | return 0; |
| 68 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 69 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | @Override |
| 71 | public int getCost() { |
| 72 | return cost; |
| 73 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 74 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 75 | public void setCost(int cost) { |
| 76 | this.cost = cost; |
| 77 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 78 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | @Override |
| 80 | public Double getCapacity() { |
| 81 | return capacity; |
| 82 | } |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 83 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 84 | public void setCapacity(Double capacity) { |
| 85 | this.capacity = capacity; |
| 86 | } |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 87 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | @Override |
| 89 | public String toString() { |
| 90 | return String.format("%s --(cap:%f Mbps)--> %s", |
| 91 | getSrcPort().toString(), |
| 92 | getCapacity(), |
| 93 | getDstPort().toString()); |
| 94 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 95 | } |