Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 3 | import net.onrc.onos.datastore.topology.RCPort; |
| 4 | import net.onrc.onos.datastore.topology.RCSwitch; |
| 5 | |
| 6 | import org.slf4j.Logger; |
| 7 | import org.slf4j.LoggerFactory; |
| 8 | |
| 9 | import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException; |
| 10 | |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 11 | /** |
| 12 | * The "NB" read-only Network Map. |
| 13 | * |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 14 | * TODO Current implementation directly read from DB, but eventually, it should |
| 15 | * read from In-memory shared Network Map instance within ONOS process. |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 18 | public class NetworkGraphImpl extends AbstractNetworkGraph { |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 19 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 20 | private static final Logger log = LoggerFactory |
| 21 | .getLogger(NetworkGraphImpl.class); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 22 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 23 | public NetworkGraphImpl() { |
| 24 | super(); |
| 25 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 26 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 27 | void addSwitch(Switch sw) { |
| 28 | if ( sw == null ) { |
| 29 | throw new IllegalArgumentException("Switch cannot be null"); |
| 30 | } |
| 31 | switches.put(sw.getDpid(), sw); |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 32 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 33 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 34 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 35 | /** |
| 36 | * Deactivate Switch (and its Ports) |
| 37 | * @param sw |
| 38 | */ |
| 39 | void deactivateSwitch(Switch sw) { |
| 40 | if ( sw == null ) { |
| 41 | throw new IllegalArgumentException("Switch cannot be null"); |
| 42 | } |
| 43 | SwitchImpl s = getSwitchImpl(sw); |
| 44 | // TODO Deactivate Switch |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 45 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 46 | // XXX Are we sure we want to deactivate Ports also? |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 47 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 48 | // TODO Auto-generated method stub |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 49 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 50 | } |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 51 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 52 | void addPort(Port port) { |
| 53 | if ( port == null ) { |
| 54 | throw new IllegalArgumentException("Port cannot be null"); |
| 55 | } |
| 56 | // TODO Auto-generated method stub |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 57 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 58 | } |
| 59 | |
| 60 | void deactivatePort(Port port) { |
| 61 | if ( port == null ) { |
| 62 | throw new IllegalArgumentException("Port cannot be null"); |
| 63 | } |
| 64 | // TODO Auto-generated method stub |
| 65 | |
| 66 | } |
| 67 | |
| 68 | void addLink(Link link) { |
| 69 | if ( link == null ) { |
| 70 | throw new IllegalArgumentException("Link cannot be null"); |
| 71 | } |
| 72 | // TODO Auto-generated method stub |
| 73 | |
| 74 | } |
| 75 | |
| 76 | void removeLink(Link link) { |
| 77 | if ( link == null ) { |
| 78 | throw new IllegalArgumentException("Link cannot be null"); |
| 79 | } |
| 80 | // TODO Auto-generated method stub |
| 81 | |
| 82 | } |
| 83 | |
| 84 | void updateDevice(Device device) { |
| 85 | if ( device == null ) { |
| 86 | throw new IllegalArgumentException("Device cannot be null"); |
| 87 | } |
| 88 | // TODO Auto-generated method stub |
| 89 | |
| 90 | } |
| 91 | |
| 92 | void removeDevice(Device device) { |
| 93 | if ( device == null ) { |
| 94 | throw new IllegalArgumentException("Device cannot be null"); |
| 95 | } |
| 96 | // TODO Auto-generated method stub |
| 97 | |
| 98 | } |
| 99 | |
| 100 | private SwitchImpl getSwitchImpl(Switch sw) { |
| 101 | if( sw instanceof SwitchImpl ) { |
| 102 | return (SwitchImpl) sw; |
| 103 | } |
| 104 | throw new ClassCastException("SwitchImpl expected, but found:" + sw.getClass().getName() ); |
| 105 | } |
| 106 | |
| 107 | // FIXME To be removed later this class should never read from DB. |
| 108 | public void readSwitchFromTopology(long dpid) { |
| 109 | SwitchImpl sw = new SwitchImpl(this); |
| 110 | |
| 111 | RCSwitch rcSwitch = new RCSwitch(dpid); |
| 112 | try { |
| 113 | rcSwitch.read(); |
| 114 | } catch (ObjectDoesntExistException e) { |
| 115 | log.warn("Tried to get a switch that doesn't exist {}", dpid); |
| 116 | return; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 119 | sw.setDpid(rcSwitch.getDpid()); |
| 120 | |
| 121 | addSwitch(sw); |
| 122 | |
| 123 | for (byte[] portId : rcSwitch.getAllPortIds()) { |
| 124 | RCPort rcPort = RCPort.createFromKey(portId); |
| 125 | try { |
| 126 | rcPort.read(); |
| 127 | |
| 128 | PortImpl port = new PortImpl(this); |
| 129 | // port.setDpid(dpid); |
| 130 | |
| 131 | // TODO why are port numbers long? |
| 132 | // port.setPortNumber((short)rcPort.getNumber()); |
| 133 | |
| 134 | port.setSwitch(sw); |
| 135 | sw.addPort(port); |
| 136 | |
| 137 | addPort(port); |
| 138 | |
| 139 | } catch (ObjectDoesntExistException e) { |
| 140 | log.warn("Tried to read port that doesn't exist", rcPort); |
| 141 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Yuta HIGUCHI | 80829d1 | 2014-02-05 20:16:56 -0800 | [diff] [blame^] | 144 | } |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 145 | |
| 146 | } |