Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.Collections; |
| 5 | import java.util.HashMap; |
| 6 | import java.util.Map; |
| 7 | |
| 8 | import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException; |
| 9 | import edu.stanford.ramcloud.JRamCloud.WrongVersionException; |
| 10 | import net.onrc.onos.datastore.topology.RCPort; |
| 11 | import net.onrc.onos.datastore.topology.RCSwitch; |
| 12 | import net.onrc.onos.ofcontroller.util.FlowEntry; |
| 13 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 14 | /** |
| 15 | * Switch Object stored in In-memory Topology. |
| 16 | * |
| 17 | * TODO REMOVE following design memo: This object itself may hold the DBObject, |
| 18 | * but this Object itself will not issue any read/write to the DataStore. |
| 19 | */ |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 20 | public class SwitchImpl extends NetworkGraphObject implements Switch { |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 21 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 22 | private long dpid; |
| 23 | private final Map<Short, Port> ports; |
| 24 | |
| 25 | public SwitchImpl(NetworkGraph graph) { |
| 26 | super(graph); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 27 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 28 | ports = new HashMap<Short, Port>(); |
| 29 | } |
| 30 | |
| 31 | @Override |
| 32 | public long getDpid() { |
| 33 | return dpid; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public Collection<Port> getPorts() { |
| 38 | return Collections.unmodifiableCollection(ports.values()); |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public Port getPort(short number) { |
| 43 | return ports.get(number); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public Collection<FlowEntry> getFlowEntries() { |
| 48 | // TODO Auto-generated method stub |
| 49 | return null; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public Iterable<Switch> getNeighbors() { |
| 54 | // TODO Auto-generated method stub |
| 55 | return null; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Link getLinkToNeighbor(long neighborDpid) { |
| 60 | for (Link link : graph.getLinksFromSwitch(dpid)) { |
| 61 | if (link.getDestinationSwitch().getDpid() == neighborDpid) { |
| 62 | return link; |
| 63 | } |
| 64 | } |
| 65 | return null; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public Collection<Device> getDevices() { |
| 70 | // TODO Auto-generated method stub |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | public void setDpid(long dpid) { |
| 75 | this.dpid = dpid; |
| 76 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 77 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 78 | public void addPort(Port port) { |
| 79 | this.ports.put(port.getNumber(), port); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public Iterable<Link> getLinks() { |
| 84 | return graph.getLinksFromSwitch(dpid); |
| 85 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 86 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 87 | public void store() { |
| 88 | RCSwitch rcSwitch = new RCSwitch(dpid); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 89 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 90 | for (Port port : ports.values()) { |
| 91 | RCPort rcPort = new RCPort(dpid, (long)port.getNumber()); |
| 92 | rcSwitch.addPortId(rcPort.getId()); |
| 93 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 94 | |
| 95 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 96 | try { |
| 97 | rcSwitch.update(); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 98 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 99 | } catch (ObjectDoesntExistException | WrongVersionException e) { |
| 100 | // TODO Auto-generated catch block |
| 101 | e.printStackTrace(); |
| 102 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame^] | 103 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 104 | } |
| 105 | } |