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 | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 3 | import java.util.Collections; |
4 | import java.util.HashSet; | ||||
5 | import java.util.Set; | ||||
6 | |||||
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 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | private Long number; |
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 | |||||
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 24 | // These needs to be ConcurrentCollecton if allowing the topology to be |
25 | // accessed concurrently | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 26 | protected Set<Device> devices; |
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 27 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 28 | public PortImpl(Topology topology, Switch parentSwitch, Long number) { |
29 | super(topology); | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 30 | this.sw = parentSwitch; |
31 | this.number = number; | ||||
32 | this.devices = new HashSet<>(); | ||||
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 33 | |
34 | switchPort = new SwitchPort(parentSwitch.getDpid(), 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 |
38 | public Long getDpid() { | ||||
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 |
43 | public Long getNumber() { | ||||
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() { | ||||
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 74 | return topology.getOutgoingLink(switchPort.dpid().value(), |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 75 | (long) switchPort.port().value()); |
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() { | ||||
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 80 | return topology.getIncomingLink(switchPort.dpid().value(), |
Jonathan Hart | 25bd53e | 2014-04-30 23:44:09 -0700 | [diff] [blame] | 81 | (long) switchPort.port().value()); |
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() { | ||||
86 | return Collections.unmodifiableSet(this.devices); | ||||
87 | } | ||||
Yuta HIGUCHI | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 88 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 89 | /** |
90 | * @param d | ||||
91 | * @return true if successfully added | ||||
92 | */ | ||||
93 | public boolean addDevice(Device d) { | ||||
94 | return this.devices.add(d); | ||||
95 | } | ||||
Yuta HIGUCHI | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 96 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 97 | /** |
98 | * @param d | ||||
99 | * @return true if device existed and was removed | ||||
100 | */ | ||||
101 | public boolean removeDevice(Device d) { | ||||
102 | return this.devices.remove(d); | ||||
103 | } | ||||
Yuta HIGUCHI | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 104 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 105 | public void removeAllDevice() { |
106 | this.devices.clear(); | ||||
107 | } | ||||
Yuta HIGUCHI | cd922f4 | 2014-02-11 18:59:11 -0800 | [diff] [blame] | 108 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 109 | @Override |
110 | public String toString() { | ||||
111 | return String.format("%d:%d", | ||||
112 | getSwitch().getDpid(), | ||||
113 | getNumber()); | ||||
114 | } | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 115 | } |