[ONOS-4164] PceManager device and link event handling
Change-Id: I55d8f60e0fcc0e23f4c14045a8e20bd89f635913 (cherry picked from commit 1d17cadb)
Showing
7 changed files
with
229 additions
and
0 deletions
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.pce.util; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | + | ||
20 | +import org.onosproject.net.ConnectPoint; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.net.Link; | ||
23 | +import org.onosproject.net.link.LinkListener; | ||
24 | +import org.onosproject.net.link.LinkService; | ||
25 | +import org.onosproject.net.Link.State; | ||
26 | + | ||
27 | +import com.google.common.collect.FluentIterable; | ||
28 | + | ||
29 | +/** | ||
30 | + * Test adapter for link service. | ||
31 | + */ | ||
32 | +public class LinkServiceAdapter implements LinkService { | ||
33 | + @Override | ||
34 | + public int getLinkCount() { | ||
35 | + return 0; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public Iterable<Link> getLinks() { | ||
40 | + return null; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public Iterable<Link> getActiveLinks() { | ||
45 | + return FluentIterable.from(getLinks()) | ||
46 | + .filter(input -> input.state() == State.ACTIVE); | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public Set<Link> getDeviceLinks(DeviceId deviceId) { | ||
51 | + return null; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public Set<Link> getDeviceEgressLinks(DeviceId deviceId) { | ||
56 | + return null; | ||
57 | + } | ||
58 | + | ||
59 | + @Override | ||
60 | + public Set<Link> getDeviceIngressLinks(DeviceId deviceId) { | ||
61 | + return null; | ||
62 | + } | ||
63 | + | ||
64 | + @Override | ||
65 | + public Set<Link> getLinks(ConnectPoint connectPoint) { | ||
66 | + return null; | ||
67 | + } | ||
68 | + | ||
69 | + @Override | ||
70 | + public Set<Link> getEgressLinks(ConnectPoint connectPoint) { | ||
71 | + return null; | ||
72 | + } | ||
73 | + | ||
74 | + @Override | ||
75 | + public Set<Link> getIngressLinks(ConnectPoint connectPoint) { | ||
76 | + return null; | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public Link getLink(ConnectPoint src, ConnectPoint dst) { | ||
81 | + return null; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public void addListener(LinkListener listener) { | ||
86 | + } | ||
87 | + | ||
88 | + @Override | ||
89 | + public void removeListener(LinkListener listener) { | ||
90 | + } | ||
91 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.pce.util; | ||
17 | + | ||
18 | +import java.util.LinkedList; | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +import org.onosproject.net.device.DeviceListener; | ||
22 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
23 | +import org.onosproject.net.Device; | ||
24 | +import org.onosproject.net.DeviceId; | ||
25 | + | ||
26 | +/** | ||
27 | + * Test fixture for the device service. | ||
28 | + */ | ||
29 | +public class MockDeviceService extends DeviceServiceAdapter { | ||
30 | + private List<Device> devices = new LinkedList<>(); | ||
31 | + private DeviceListener listener; | ||
32 | + | ||
33 | + public void addDevice(Device dev) { | ||
34 | + devices.add(dev); | ||
35 | + } | ||
36 | + | ||
37 | + public void removeDevice(Device dev) { | ||
38 | + devices.remove(dev); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public Device getDevice(DeviceId deviceId) { | ||
43 | + for (Device dev : devices) { | ||
44 | + if (dev.id().equals(deviceId)) { | ||
45 | + return dev; | ||
46 | + } | ||
47 | + } | ||
48 | + return null; | ||
49 | + } | ||
50 | + | ||
51 | + @Override | ||
52 | + public Iterable<Device> getAvailableDevices() { | ||
53 | + return devices; | ||
54 | + } | ||
55 | + | ||
56 | + @Override | ||
57 | + public void addListener(DeviceListener listener) { | ||
58 | + this.listener = listener; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Get the listener. | ||
63 | + */ | ||
64 | + public DeviceListener getListener() { | ||
65 | + return listener; | ||
66 | + } | ||
67 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.pce.util; | ||
17 | + | ||
18 | +import org.onosproject.net.Link; | ||
19 | +import org.onosproject.net.link.LinkServiceAdapter; | ||
20 | +import org.onosproject.net.link.LinkListener; | ||
21 | + | ||
22 | +import java.util.ArrayList; | ||
23 | +import java.util.List; | ||
24 | + | ||
25 | +/** | ||
26 | + * Test fixture for the link service. | ||
27 | + */ | ||
28 | +public class MockLinkService extends LinkServiceAdapter { | ||
29 | + List<Link> links = new ArrayList<>(); | ||
30 | + LinkListener listener; | ||
31 | + | ||
32 | + @Override | ||
33 | + public int getLinkCount() { | ||
34 | + return links.size(); | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public Iterable<Link> getLinks() { | ||
39 | + return links; | ||
40 | + } | ||
41 | + | ||
42 | + @Override | ||
43 | + public void addListener(LinkListener listener) { | ||
44 | + this.listener = listener; | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Get listener. | ||
49 | + */ | ||
50 | + public LinkListener getListener() { | ||
51 | + return listener; | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
55 | + * Add link. | ||
56 | + * | ||
57 | + * @param link needs to be added to list | ||
58 | + */ | ||
59 | + public void addLink(Link link) { | ||
60 | + links.add(link); | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * Delete link. | ||
65 | + * | ||
66 | + * @param link needs to be deleted from list | ||
67 | + */ | ||
68 | + public void removeLink(Link link) { | ||
69 | + links.remove(link); | ||
70 | + } | ||
71 | +} |
-
Please register or login to post a comment