blob: ef04165a0150533f512f0f9f1ef6aa48f0c0bf2e [file] [log] [blame]
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +00001/*
2 * Copyright 2016-present Open Networking Foundation
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 */
16package org.opencord.cordmcast;
17
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000018import java.util.Arrays;
19import java.util.HashMap;
20import java.util.HashSet;
21import java.util.Iterator;
22import java.util.List;
23import java.util.Map;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000024import java.util.Set;
25
Esin Karaman996177c2020-03-05 13:21:09 +000026import org.onlab.packet.Ip4Address;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000027import org.onlab.packet.IpAddress;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000028import org.onosproject.TestApplicationId;
29import org.onosproject.core.ApplicationId;
30import org.onosproject.core.CoreServiceAdapter;
31import org.onosproject.mastership.MastershipServiceAdapter;
32import org.onosproject.mcast.api.McastRoute;
Esin Karaman996177c2020-03-05 13:21:09 +000033import org.onosproject.net.AnnotationKeys;
34import org.onosproject.net.Annotations;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000035import org.onosproject.net.ConnectPoint;
Esin Karaman996177c2020-03-05 13:21:09 +000036import org.onosproject.net.DefaultAnnotations;
37import org.onosproject.net.DefaultDevice;
38import org.onosproject.net.Device;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000039import org.onosproject.net.DeviceId;
40import org.onosproject.net.HostId;
41import org.onosproject.net.PortNumber;
Esin Karaman996177c2020-03-05 13:21:09 +000042import org.onosproject.net.SparseAnnotations;
43import org.onosproject.net.device.DeviceServiceAdapter;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000044import org.onosproject.net.flow.TrafficSelector;
45import org.onosproject.net.flow.TrafficTreatment;
46import org.onosproject.net.flow.criteria.Criterion;
47import org.onosproject.net.flow.criteria.IPCriterion;
48import org.onosproject.net.flow.instructions.Instruction;
49import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
50import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter;
51import org.onosproject.net.flowobjective.ForwardingObjective;
52import org.onosproject.net.flowobjective.NextObjective;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000053
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000054import com.google.common.collect.ImmutableMap;
Esin Karaman996177c2020-03-05 13:21:09 +000055import org.opencord.sadis.BandwidthProfileInformation;
56import org.opencord.sadis.BaseInformationService;
57import org.opencord.sadis.SadisService;
58import org.opencord.sadis.SubscriberAndDeviceInformation;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000059
60public class McastTestBase {
61
62 // Map to store the forwardingObjective in flowObjectiveService.forward()
63 Map<DeviceId, ForwardingObjective> forwardMap = new HashMap<>();
64 // Map to store the nextObjective in flowObjectiveService.next()
65 Map<DeviceId, NextObjective> nextMap = new HashMap<>();
66 // Device configuration
67 protected static final DeviceId DEVICE_ID_OF_A = DeviceId.deviceId("of:00000a0a0a0a0a00");
68 // Port number
69 protected static final PortNumber PORT_A = PortNumber.portNumber(1048576);
70 protected static final PortNumber PORT_B = PortNumber.portNumber(16);
71 protected static final PortNumber PORT_C = PortNumber.portNumber(24);
72
73 // Connect Point for creating source and sink
74 protected static final ConnectPoint CONNECT_POINT_A = new ConnectPoint(DEVICE_ID_OF_A, PORT_A);
75 protected static final ConnectPoint CONNECT_POINT_B = new ConnectPoint(DEVICE_ID_OF_A, PORT_B);
76 protected static final ConnectPoint CONNECT_POINT_C = new ConnectPoint(DEVICE_ID_OF_A, PORT_C);
77
Esin Karaman996177c2020-03-05 13:21:09 +000078 // serial number of the device A
79 protected static final String SERIAL_NUMBER_OF_DEVICE_A = "serialNumberOfDevA";
80 // Management ip address of the device A
81 protected static final Ip4Address MANAGEMENT_IP_OF_A = Ip4Address.valueOf("10.177.125.4");
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000082 //Host id configuration
83 protected static final HostId HOST_ID_NONE = HostId.NONE;
84 // Source connect point
85 protected static final Set<ConnectPoint> SOURCES_CP = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_A));
86 Map<HostId, Set<ConnectPoint>> sources = ImmutableMap.of(HOST_ID_NONE, SOURCES_CP);
87
88 protected static final IpAddress MULTICAST_IP = IpAddress.valueOf("224.0.0.22");
89 // Creating dummy route with IGMP type.
90 McastRoute route1 = new McastRoute(null, MULTICAST_IP, McastRoute.Type.IGMP);
91
92 // Creating empty sink used in prevRoute
93 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList());
94 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
95
96 // Creating empty source
97 Set<ConnectPoint> sourceCp = new HashSet<ConnectPoint>(Arrays.asList());
98 Map<HostId, Set<ConnectPoint>> emptySource = ImmutableMap.of(HOST_ID_NONE, sourceCp);
99
100 // Flag to check unknown olt device
101 boolean knownOltFlag = false;
102
103 class MockCoreService extends CoreServiceAdapter {
104 @Override
105 public ApplicationId registerApplication(String name) {
106 ApplicationId testApplicationId = TestApplicationId.create("org.opencord.cordmcast");
107 return testApplicationId;
108 }
109 }
110
111 class MockFlowObjectiveService extends FlowObjectiveServiceAdapter {
112 @Override
113 public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
114 synchronized (forwardMap) {
115 forwardMap.put(deviceId, forwardingObjective);
116 forwardMap.notify();
117 }
118 }
119
120 @Override
121 public void next(DeviceId deviceId, NextObjective nextObjective) {
122 nextMap.put(deviceId, nextObjective);
123 }
124 }
125
126 class TestMastershipService extends MastershipServiceAdapter {
127 @Override
128 public boolean isLocalMaster(DeviceId deviceId) {
129 return true;
130 }
131 }
132
Esin Karaman996177c2020-03-05 13:21:09 +0000133 protected class MockSadisService implements SadisService {
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000134
Esin Karaman996177c2020-03-05 13:21:09 +0000135 @Override
136 public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() {
137 return new MockSubService();
138 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000139
Esin Karaman996177c2020-03-05 13:21:09 +0000140 @Override
141 public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() {
142 return null;
143 }
144 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000145
Esin Karaman996177c2020-03-05 13:21:09 +0000146 private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> {
147 MockSubscriberAndDeviceInformation deviceA =
148 new MockSubscriberAndDeviceInformation(SERIAL_NUMBER_OF_DEVICE_A, MANAGEMENT_IP_OF_A);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000149
Esin Karaman996177c2020-03-05 13:21:09 +0000150 @Override
151 public SubscriberAndDeviceInformation get(String id) {
152 return SERIAL_NUMBER_OF_DEVICE_A.equals(id) ? deviceA : null;
153 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000154
Esin Karaman996177c2020-03-05 13:21:09 +0000155 @Override
156 public void invalidateAll() {
157 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000158
Esin Karaman996177c2020-03-05 13:21:09 +0000159 @Override
160 public void invalidateId(String id) {
161 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000162
Esin Karaman996177c2020-03-05 13:21:09 +0000163 @Override
164 public SubscriberAndDeviceInformation getfromCache(String id) {
165 return null;
166 }
167 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000168
Esin Karaman996177c2020-03-05 13:21:09 +0000169 private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation {
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000170
Esin Karaman996177c2020-03-05 13:21:09 +0000171 MockSubscriberAndDeviceInformation(String id, Ip4Address ipAddress) {
172 this.setId(id);
173 this.setIPAddress(ipAddress);
174 this.setUplinkPort((int) PORT_A.toLong());
175 }
176 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000177
Esin Karaman996177c2020-03-05 13:21:09 +0000178 class MockDeviceService extends DeviceServiceAdapter {
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000179
Esin Karaman996177c2020-03-05 13:21:09 +0000180 @Override
181 public Device getDevice(DeviceId deviceId) {
182 if (DEVICE_ID_OF_A.equals(deviceId)) {
183 DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder()
184 .set(AnnotationKeys.MANAGEMENT_ADDRESS, MANAGEMENT_IP_OF_A.toString());
185 SparseAnnotations annotations = annotationsBuilder.build();
186 Annotations[] da = {annotations};
187
188 Device deviceA = new DefaultDevice(null, DEVICE_ID_OF_A, Device.Type.OTHER, "", "",
189 "", SERIAL_NUMBER_OF_DEVICE_A, null, da);
190 return deviceA;
191 } else {
192 knownOltFlag = true;
193 }
194 return null;
195 }
196 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000197
198 public OutputInstruction outputPort(TrafficTreatment trafficTreatment) {
199 List<Instruction> listOfInstructions = trafficTreatment.allInstructions();
200 OutputInstruction output = null;
201 for (Instruction intruction : listOfInstructions) {
202 output = (OutputInstruction) intruction;
203 }
204 return output;
205 }
206
207 public IPCriterion ipAddress(TrafficSelector trafficSelector) {
208 Set<Criterion> criterionSet = trafficSelector.criteria();
209 Iterator<Criterion> it = criterionSet.iterator();
210 IPCriterion ipCriterion = null;
211 while (it.hasNext()) {
212 Criterion criteria = it.next();
213 if (Criterion.Type.IPV4_DST == criteria.type()) {
214 ipCriterion = (IPCriterion) criteria;
215 }
216 }
217 return (IPCriterion) ipCriterion;
218 }
219
220}