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 | |||||
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 7 | /** |
8 | * Port Object stored in In-memory Topology. | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 9 | * <p/> |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 10 | * TODO REMOVE following design memo: This object itself may hold the DBObject, |
11 | * but this Object itself will not issue any read/write to the DataStore. | ||||
12 | */ | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 13 | public class PortImpl extends NetworkGraphObject implements Port { |
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 14 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 15 | private Switch sw; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 16 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 17 | private Long number; |
18 | private String description; | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 19 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 20 | protected Link outgoingLink; |
21 | protected Link incomingLink; | ||||
22 | // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently | ||||
23 | protected Set<Device> devices; | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 24 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 25 | public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) { |
26 | super(graph); | ||||
27 | this.sw = parentSwitch; | ||||
28 | this.number = number; | ||||
29 | this.devices = new HashSet<>(); | ||||
30 | } | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 31 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 32 | @Override |
33 | public Long getDpid() { | ||||
34 | return sw.getDpid(); | ||||
35 | } | ||||
Yuta HIGUCHI | ea516d6 | 2014-02-13 15:59:32 -0800 | [diff] [blame] | 36 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 37 | @Override |
38 | public Long getNumber() { | ||||
39 | return number; | ||||
40 | } | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 41 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 42 | @Override |
43 | public String getDescription() { | ||||
44 | return description; | ||||
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 | public void setDescription(String description) { |
48 | this.description = description; | ||||
49 | } | ||||
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 50 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 51 | @Override |
52 | public Long getHardwareAddress() { | ||||
53 | // TODO Auto-generated method stub | ||||
54 | return 0L; | ||||
55 | } | ||||
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 56 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 57 | @Override |
58 | public Switch getSwitch() { | ||||
59 | return sw; | ||||
60 | } | ||||
Yuta HIGUCHI | 181d34d | 2014-02-05 15:05:46 -0800 | [diff] [blame] | 61 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 62 | @Override |
63 | public Link getOutgoingLink() { | ||||
64 | return outgoingLink; | ||||
65 | } | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 66 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 67 | @Override |
68 | public Link getIncomingLink() { | ||||
69 | return incomingLink; | ||||
70 | } | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 71 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 72 | @Override |
73 | public Iterable<Device> getDevices() { | ||||
74 | return Collections.unmodifiableSet(this.devices); | ||||
75 | } | ||||
Yuta HIGUCHI | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 76 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 77 | public void setOutgoingLink(Link link) { |
78 | outgoingLink = link; | ||||
79 | } | ||||
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 80 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 81 | public void setIncomingLink(Link link) { |
82 | incomingLink = link; | ||||
83 | } | ||||
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 84 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 85 | /** |
86 | * @param d | ||||
87 | * @return true if successfully added | ||||
88 | */ | ||||
89 | public boolean addDevice(Device d) { | ||||
90 | return this.devices.add(d); | ||||
91 | } | ||||
Yuta HIGUCHI | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 92 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 93 | /** |
94 | * @param d | ||||
95 | * @return true if device existed and was removed | ||||
96 | */ | ||||
97 | public boolean removeDevice(Device d) { | ||||
98 | return this.devices.remove(d); | ||||
99 | } | ||||
Yuta HIGUCHI | 4bfdd53 | 2014-02-07 13:47:36 -0800 | [diff] [blame] | 100 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 101 | public void removeAllDevice() { |
102 | this.devices.clear(); | ||||
103 | } | ||||
Yuta HIGUCHI | cd922f4 | 2014-02-11 18:59:11 -0800 | [diff] [blame] | 104 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 105 | @Override |
106 | public String toString() { | ||||
107 | return String.format("%d:%d", | ||||
108 | getSwitch().getDpid(), | ||||
109 | getNumber()); | ||||
110 | } | ||||
Jonathan Hart | 062a2e8 | 2014-02-03 09:41:57 -0800 | [diff] [blame] | 111 | } |