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 | db1b830 | 2014-06-26 10:50:39 -0700 | [diff] [blame^] | 3 | import java.util.Map; |
| 4 | |
| 5 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.util.SwitchPort; |
| 7 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 8 | /** |
| 9 | * Link Object stored in In-memory Topology. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 10 | * <p/> |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 11 | * TODO REMOVE following design memo: This object itself may hold the DBObject, |
| 12 | * but this Object itself will not issue any read/write to the DataStore. |
| 13 | */ |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 14 | public class LinkImpl extends TopologyObject implements Link { |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 15 | private SwitchPort srcPort; |
| 16 | private SwitchPort dstPort; |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 17 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 18 | protected static final Double DEFAULT_CAPACITY = Double.POSITIVE_INFINITY; |
| 19 | protected Double capacity = DEFAULT_CAPACITY; |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 20 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 21 | protected static final int DEFAULT_COST = 1; |
| 22 | protected int cost = DEFAULT_COST; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 23 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Constructor for when a link is read from the database and the Ports |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 26 | * already exist in the in-memory topology. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | * |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 28 | * @param topology |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 29 | * @param srcPort |
| 30 | * @param dstPort |
| 31 | */ |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 32 | public LinkImpl(Topology topology, Port srcPort, Port dstPort) { |
| 33 | super(topology); |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 34 | this.srcPort = srcPort.asSwitchPort(); |
| 35 | this.dstPort = dstPort.asSwitchPort(); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 36 | } |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 37 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 38 | @Override |
| 39 | public Switch getSrcSwitch() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 40 | return topology.getSwitch(srcPort.dpid().value()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 42 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | @Override |
| 44 | public Port getSrcPort() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 45 | return topology.getPort(srcPort.dpid().value(), (long) srcPort.port().value()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 46 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 47 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | @Override |
| 49 | public Switch getDstSwitch() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 50 | return topology.getSwitch(dstPort.dpid().value()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | } |
Pavlin Radoslavov | 7c8f69a | 2014-02-19 19:01:45 -0800 | [diff] [blame] | 52 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 53 | @Override |
| 54 | public Port getDstPort() { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 55 | return topology.getPort(dstPort.dpid().value(), (long) dstPort.port().value()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 56 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 57 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 58 | @Override |
| 59 | public long getLastSeenTime() { |
| 60 | // TODO Auto-generated method stub |
| 61 | return 0; |
| 62 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 63 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | @Override |
| 65 | public int getCost() { |
| 66 | return cost; |
| 67 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 68 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 69 | public void setCost(int cost) { |
| 70 | this.cost = cost; |
| 71 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 72 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 73 | @Override |
| 74 | public Double getCapacity() { |
| 75 | return capacity; |
| 76 | } |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 77 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | public void setCapacity(Double capacity) { |
| 79 | this.capacity = capacity; |
| 80 | } |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 81 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | @Override |
Yuta HIGUCHI | db1b830 | 2014-06-26 10:50:39 -0700 | [diff] [blame^] | 83 | public String getStringAttribute(String attr) { |
| 84 | throw new UnsupportedOperationException("Not implemented yet"); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", |
| 89 | justification = "getStringAttribute might return null once implemented") |
| 90 | public String getStringAttribute(String attr, String def) { |
| 91 | final String v = getStringAttribute(attr); |
| 92 | if (v == null) { |
| 93 | return def; |
| 94 | } else { |
| 95 | return v; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public Map<String, String> getAllStringAttributes() { |
| 101 | throw new UnsupportedOperationException("Not implemented yet"); |
| 102 | } |
| 103 | |
| 104 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 105 | public String toString() { |
| 106 | return String.format("%s --(cap:%f Mbps)--> %s", |
| 107 | getSrcPort().toString(), |
| 108 | getCapacity(), |
| 109 | getDstPort().toString()); |
| 110 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 111 | } |