Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.app; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.HashMap; |
| 5 | import java.util.LinkedList; |
| 6 | |
| 7 | /** |
| 8 | * This code is valid for the architectural study purpose only. |
| 9 | * @author Toshio Koide (t-koide@onlab.us) |
| 10 | */ |
| 11 | public class Switch extends NetworkGraphEntity { |
| 12 | protected HashMap<Integer, SwitchPort> ports; |
| 13 | protected String name; |
| 14 | |
| 15 | public Switch(NetworkGraph graph, String name) { |
| 16 | super(graph); |
| 17 | this.name = name; |
| 18 | ports = new HashMap<Integer, SwitchPort>(); |
| 19 | } |
| 20 | |
| 21 | public SwitchPort addPort(Integer i) { |
| 22 | SwitchPort port = new SwitchPort(this, i); |
| 23 | ports.put(port.getPortNumber(), port); |
| 24 | return port; |
| 25 | } |
| 26 | |
| 27 | public SwitchPort getPort(Integer i) { |
| 28 | return ports.get(i); |
| 29 | } |
| 30 | |
| 31 | public Collection<SwitchPort> getPorts() { |
| 32 | return ports.values(); |
| 33 | } |
| 34 | |
| 35 | public Collection<Link> getAdjLinks() { |
| 36 | LinkedList<Link> links = new LinkedList<Link>(); |
| 37 | for (SwitchPort port: getPorts()) { |
| 38 | Link link = port.getOutgointLink(); |
| 39 | if (link != null) { |
| 40 | links.add(link); |
| 41 | } |
| 42 | } |
| 43 | return links; |
| 44 | } |
| 45 | |
| 46 | public String getName() { |
| 47 | return name; |
| 48 | } |
| 49 | |
| 50 | } |