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; |
Yuta HIGUCHI | db1b830 | 2014-06-26 10:50:39 -0700 | [diff] [blame] | 4 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.Dpid; |
| 6 | import net.onrc.onos.core.util.PortNumber; |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.util.SwitchPort; |
| 8 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 9 | /** |
| 10 | * Port Object stored in In-memory Topology. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 11 | * <p/> |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 12 | * TODO REMOVE following design memo: This object itself may hold the DBObject, |
| 13 | * but this Object itself will not issue any read/write to the DataStore. |
| 14 | */ |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 15 | public class PortImpl extends TopologyObject implements Port { |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 16 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 17 | private Switch sw; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 18 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 19 | private PortNumber number; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | private String description; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 21 | |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 22 | private final SwitchPort switchPort; |
| 23 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 24 | public PortImpl(Topology topology, Switch parentSwitch, PortNumber number) { |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 25 | super(topology); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 26 | this.sw = parentSwitch; |
| 27 | this.number = number; |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 28 | |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 29 | switchPort = new SwitchPort(parentSwitch.getDpid(), |
| 30 | number); |
| 31 | } |
| 32 | |
| 33 | public PortImpl(Topology topology, Switch parentSwitch, Long number) { |
| 34 | this(topology, parentSwitch, new PortNumber(number.shortValue())); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 36 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 37 | @Override |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 38 | public Dpid getDpid() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 39 | return sw.getDpid(); |
| 40 | } |
Yuta HIGUCHI | ea516d6 | 2014-02-13 15:59:32 -0800 | [diff] [blame] | 41 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | @Override |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 43 | public PortNumber getNumber() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | return number; |
| 45 | } |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 46 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 47 | @Override |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 48 | public SwitchPort asSwitchPort() { |
| 49 | return switchPort; |
| 50 | } |
| 51 | |
| 52 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 53 | public String getDescription() { |
| 54 | return description; |
| 55 | } |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 56 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 57 | public void setDescription(String description) { |
| 58 | this.description = description; |
| 59 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 60 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 61 | @Override |
| 62 | public Long getHardwareAddress() { |
| 63 | // TODO Auto-generated method stub |
| 64 | return 0L; |
| 65 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 66 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | @Override |
| 68 | public Switch getSwitch() { |
| 69 | return sw; |
| 70 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 71 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | @Override |
| 73 | public Link getOutgoingLink() { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 74 | return topology.getOutgoingLink(switchPort.dpid(), |
| 75 | switchPort.port()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 76 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 77 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 78 | @Override |
| 79 | public Link getIncomingLink() { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 80 | return topology.getIncomingLink(switchPort.dpid(), |
| 81 | switchPort.port()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 82 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 83 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 84 | @Override |
| 85 | public Iterable<Device> getDevices() { |
Yuta HIGUCHI | fa74284 | 2014-07-03 22:35:13 -0700 | [diff] [blame] | 86 | return topology.getDevices(this.asSwitchPort()); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 87 | } |
Yuta HIGUCHI | cd922f4 | 2014-02-11 18:59:11 -0800 | [diff] [blame] | 88 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | @Override |
Yuta HIGUCHI | db1b830 | 2014-06-26 10:50:39 -0700 | [diff] [blame] | 90 | public String getStringAttribute(String attr) { |
| 91 | throw new UnsupportedOperationException("Not implemented yet"); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", |
| 96 | justification = "getStringAttribute might return null once implemented") |
| 97 | public String getStringAttribute(String attr, String def) { |
| 98 | final String v = getStringAttribute(attr); |
| 99 | if (v == null) { |
| 100 | return def; |
| 101 | } else { |
| 102 | return v; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Map<String, String> getAllStringAttributes() { |
| 108 | throw new UnsupportedOperationException("Not implemented yet"); |
| 109 | } |
| 110 | |
| 111 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 112 | public String toString() { |
Yuta HIGUCHI | 8f3dfa3 | 2014-06-25 00:14:25 -0700 | [diff] [blame] | 113 | return String.format("%s:%s", |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 114 | getSwitch().getDpid(), |
| 115 | getNumber()); |
| 116 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 117 | } |