Added simple link manager implementation.
Added link admin stuff; unit tests to come.
Showing
2 changed files
with
127 additions
and
1 deletions
... | @@ -50,7 +50,7 @@ public class SimpleLinkManager | ... | @@ -50,7 +50,7 @@ public class SimpleLinkManager |
50 | private final SimpleLinkStore store = new SimpleLinkStore(); | 50 | private final SimpleLinkStore store = new SimpleLinkStore(); |
51 | 51 | ||
52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
53 | - private EventDeliveryService eventDispatcher; | 53 | + protected EventDeliveryService eventDispatcher; |
54 | 54 | ||
55 | @Activate | 55 | @Activate |
56 | public void activate() { | 56 | public void activate() { | ... | ... |
net/core/trivial/src/test/java/org/onlab/onos/net/trivial/impl/SimpleLinkManagerTest.java
0 → 100644
1 | +package org.onlab.onos.net.trivial.impl; | ||
2 | + | ||
3 | +import org.junit.After; | ||
4 | +import org.junit.Before; | ||
5 | +import org.junit.Test; | ||
6 | +import org.onlab.onos.event.Event; | ||
7 | +import org.onlab.onos.net.Device; | ||
8 | +import org.onlab.onos.net.DeviceId; | ||
9 | +import org.onlab.onos.net.MastershipRole; | ||
10 | +import org.onlab.onos.net.Port; | ||
11 | +import org.onlab.onos.net.PortNumber; | ||
12 | +import org.onlab.onos.net.device.DefaultDeviceDescription; | ||
13 | +import org.onlab.onos.net.device.DefaultPortDescription; | ||
14 | +import org.onlab.onos.net.device.DeviceAdminService; | ||
15 | +import org.onlab.onos.net.device.DeviceDescription; | ||
16 | +import org.onlab.onos.net.device.DeviceEvent; | ||
17 | +import org.onlab.onos.net.device.DeviceListener; | ||
18 | +import org.onlab.onos.net.device.DeviceProvider; | ||
19 | +import org.onlab.onos.net.device.DeviceProviderRegistry; | ||
20 | +import org.onlab.onos.net.device.DeviceProviderService; | ||
21 | +import org.onlab.onos.net.device.DeviceService; | ||
22 | +import org.onlab.onos.net.device.PortDescription; | ||
23 | +import org.onlab.onos.net.link.LinkAdminService; | ||
24 | +import org.onlab.onos.net.link.LinkEvent; | ||
25 | +import org.onlab.onos.net.link.LinkListener; | ||
26 | +import org.onlab.onos.net.link.LinkProvider; | ||
27 | +import org.onlab.onos.net.link.LinkProviderRegistry; | ||
28 | +import org.onlab.onos.net.link.LinkProviderService; | ||
29 | +import org.onlab.onos.net.link.LinkService; | ||
30 | +import org.onlab.onos.net.provider.AbstractProvider; | ||
31 | +import org.onlab.onos.net.provider.ProviderId; | ||
32 | + | ||
33 | +import java.util.ArrayList; | ||
34 | +import java.util.Iterator; | ||
35 | +import java.util.List; | ||
36 | + | ||
37 | +import static org.junit.Assert.*; | ||
38 | +import static org.onlab.onos.net.Device.Type.SWITCH; | ||
39 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
40 | +import static org.onlab.onos.net.device.DeviceEvent.Type.*; | ||
41 | + | ||
42 | +/** | ||
43 | + * Test codifying the link service & link provider service contracts. | ||
44 | + */ | ||
45 | +public class SimpleLinkManagerTest { | ||
46 | + | ||
47 | + private static final ProviderId PID = new ProviderId("foo"); | ||
48 | + private static final DeviceId DID1 = deviceId("of:foo"); | ||
49 | + private static final DeviceId DID2 = deviceId("of:bar"); | ||
50 | + private static final String MFR = "whitebox"; | ||
51 | + private static final String HW = "1.1.x"; | ||
52 | + private static final String SW1 = "3.8.1"; | ||
53 | + private static final String SW2 = "3.9.5"; | ||
54 | + private static final String SN = "43311-12345"; | ||
55 | + | ||
56 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
57 | + private static final PortNumber P2 = PortNumber.portNumber(2); | ||
58 | + private static final PortNumber P3 = PortNumber.portNumber(3); | ||
59 | + | ||
60 | + | ||
61 | + private SimpleLinkManager mgr; | ||
62 | + | ||
63 | + protected LinkService service; | ||
64 | + protected LinkAdminService admin; | ||
65 | + protected LinkProviderRegistry registry; | ||
66 | + protected LinkProviderService providerService; | ||
67 | + protected TestProvider provider; | ||
68 | + protected TestListener listener = new TestListener(); | ||
69 | + | ||
70 | + @Before | ||
71 | + public void setUp() { | ||
72 | + mgr = new SimpleLinkManager(); | ||
73 | + service = mgr; | ||
74 | + admin = mgr; | ||
75 | + registry = mgr; | ||
76 | + mgr.eventDispatcher = new TestEventDispatcher(); | ||
77 | + mgr.activate(); | ||
78 | + | ||
79 | + service.addListener(listener); | ||
80 | + | ||
81 | + provider = new TestProvider(); | ||
82 | + providerService = registry.register(provider); | ||
83 | + assertTrue("provider should be registered", | ||
84 | + registry.getProviders().contains(provider.id())); | ||
85 | + } | ||
86 | + | ||
87 | + @After | ||
88 | + public void tearDown() { | ||
89 | + registry.unregister(provider); | ||
90 | + assertFalse("provider should not be registered", | ||
91 | + registry.getProviders().contains(provider.id())); | ||
92 | + service.removeListener(listener); | ||
93 | + mgr.deactivate(); | ||
94 | + } | ||
95 | + | ||
96 | + | ||
97 | + protected void validateEvents(Enum... types) { | ||
98 | + int i = 0; | ||
99 | + assertEquals("wrong events received", types.length, listener.events.size()); | ||
100 | + for (Event event : listener.events) { | ||
101 | + assertEquals("incorrect event type", types[i], event.type()); | ||
102 | + i++; | ||
103 | + } | ||
104 | + listener.events.clear(); | ||
105 | + } | ||
106 | + | ||
107 | + | ||
108 | + private class TestProvider extends AbstractProvider implements LinkProvider { | ||
109 | + private Device deviceReceived; | ||
110 | + private MastershipRole roleReceived; | ||
111 | + | ||
112 | + public TestProvider() { | ||
113 | + super(PID); | ||
114 | + } | ||
115 | + } | ||
116 | + | ||
117 | + private static class TestListener implements LinkListener { | ||
118 | + final List<LinkEvent> events = new ArrayList<>(); | ||
119 | + | ||
120 | + @Override | ||
121 | + public void event(LinkEvent event) { | ||
122 | + events.add(event); | ||
123 | + } | ||
124 | + } | ||
125 | + | ||
126 | +} |
-
Please register or login to post a comment