SEBA-815 Multi Tcont support by OLT app.
Change-Id: I024ef2fcb3d3e59cc86bd2088726ae513fcff796
diff --git a/app/src/test/java/org/opencord/olt/impl/OltFlowTest.java b/app/src/test/java/org/opencord/olt/impl/OltFlowTest.java
new file mode 100644
index 0000000..8a80ee0
--- /dev/null
+++ b/app/src/test/java/org/opencord/olt/impl/OltFlowTest.java
@@ -0,0 +1,374 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.olt.impl;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ListMultimap;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.EthType;
+import org.onlab.packet.VlanId;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.cluster.RoleInfo;
+import org.onosproject.mastership.MastershipInfo;
+import org.onosproject.mastership.MastershipListener;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flow.criteria.Criterion;
+import org.onosproject.net.flow.criteria.EthTypeCriterion;
+import org.onosproject.net.flow.criteria.PortCriterion;
+import org.onosproject.net.flow.criteria.VlanIdCriterion;
+import org.onosproject.net.flow.instructions.Instruction;
+import org.onosproject.net.flow.instructions.Instructions;
+import org.onosproject.net.flow.instructions.L2ModificationInstruction;
+import org.onosproject.net.flowobjective.FilteringObjQueueKey;
+import org.onosproject.net.flowobjective.FilteringObjective;
+import org.onosproject.net.flowobjective.ForwardingObjQueueKey;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.NextObjQueueKey;
+import org.onosproject.net.flowobjective.NextObjective;
+import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.meter.MeterId;
+import org.onosproject.net.meter.MeterKey;
+import org.opencord.sadis.BandwidthProfileInformation;
+import org.opencord.sadis.UniTagInformation;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+public class OltFlowTest extends TestBase {
+ private OltFlowService oltFlowService;
+
+ PortNumber uniPortNumber = PortNumber.portNumber(1);
+ PortNumber nniPortNumber = PortNumber.portNumber(65535);
+
+ UniTagInformation.Builder tagInfoBuilder = new UniTagInformation.Builder();
+ UniTagInformation uniTagInfo = tagInfoBuilder.setUniTagMatch(VlanId.vlanId((short) 35))
+ .setPonCTag(VlanId.vlanId((short) 33))
+ .setPonSTag(VlanId.vlanId((short) 7))
+ .setDsPonCTagPriority(0)
+ .setUsPonSTagPriority(0)
+ .setTechnologyProfileId(64)
+ .setDownstreamBandwidthProfile(dsBpId)
+ .setUpstreamBandwidthProfile(usBpId)
+ .build();
+
+ @Before
+ public void setUp() {
+ oltFlowService = new OltFlowService();
+ oltFlowService.oltMeterService = new MockOltMeterService();
+ oltFlowService.flowObjectiveService = new MockOltFlowObjectiveService();
+ oltFlowService.mastershipService = new MockMastershipService();
+ oltFlowService.sadisService = new MockSadisService();
+ oltFlowService.bpService = oltFlowService.sadisService.getBandwidthProfileService();
+ oltFlowService.appId = appId;
+ }
+
+ @Test
+ public void testDhcpFiltering() {
+ oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, uniTagInfo,
+ true, true);
+ oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, uniTagInfo,
+ false, true);
+ oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, dsMeterId, uniTagInfo,
+ true, false);
+ oltFlowService.processDhcpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, uniTagInfo,
+ false, false);
+ }
+
+ @Test
+ public void testIgmpFiltering() {
+ oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, uniTagInfo,
+ true, true);
+ oltFlowService.processIgmpFilteringObjectives(DEVICE_ID_1, uniPortNumber, usMeterId, uniTagInfo,
+ false, true);
+ }
+
+ @Test
+ public void testEapolFiltering() {
+ addBandwidthProfile(uniTagInfo.getUpstreamBandwidthProfile());
+ oltFlowService.enableEapol = true;
+
+ //will install
+ oltFlowService.processEapolFilteringObjectives(DEVICE_ID_1, uniPortNumber,
+ uniTagInfo.getUpstreamBandwidthProfile(), new CompletableFuture<>(),
+ uniTagInfo.getUniTagMatch(), true);
+
+ //bp profile doesn't exist
+ oltFlowService.processEapolFilteringObjectives(DEVICE_ID_1, uniPortNumber,
+ uniTagInfo.getDownstreamBandwidthProfile(), new CompletableFuture<>(),
+ uniTagInfo.getUniTagMatch(), true);
+ }
+
+ @Test
+ public void testLldpFiltering() {
+ oltFlowService.processLldpFilteringObjective(DEVICE_ID_1, nniPortNumber, true);
+ oltFlowService.processLldpFilteringObjective(DEVICE_ID_1, nniPortNumber, false);
+ }
+
+ @Test
+ public void testNniFiltering() {
+ oltFlowService.enableDhcpOnProvisioning = true;
+ oltFlowService.enableIgmpOnProvisioning = true;
+ oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, true);
+ oltFlowService.processNniFilteringObjectives(DEVICE_ID_1, nniPortNumber, false);
+ }
+
+ @Test
+ public void testUpBuilder() {
+ ForwardingObjective objective =
+ oltFlowService.createUpBuilder(nniPortNumber, uniPortNumber, usMeterId, uniTagInfo).add();
+ checkObjective(objective, true);
+ }
+
+ @Test
+ public void testDownBuilder() {
+ ForwardingObjective objective =
+ oltFlowService.createDownBuilder(nniPortNumber, uniPortNumber, dsMeterId, uniTagInfo).remove();
+ checkObjective(objective, false);
+ }
+
+ private void checkObjective(ForwardingObjective fwd, boolean upstream) {
+ TrafficTreatment treatment = fwd.treatment();
+
+ //check instructions
+ Set<Instructions.MeterInstruction> meters = treatment.meters();
+ assert !meters.isEmpty();
+
+ Instructions.MetadataInstruction writeMetadata = treatment.writeMetadata();
+ assert writeMetadata != null;
+
+ List<Instruction> immediateInstructions = treatment.immediate();
+ Optional<Instruction> vlanInstruction = immediateInstructions.stream()
+ .filter(i -> i.type() == Instruction.Type.L2MODIFICATION)
+ .filter(i -> ((L2ModificationInstruction) i).subtype() ==
+ L2ModificationInstruction.L2SubType.VLAN_PUSH ||
+ ((L2ModificationInstruction) i).subtype() ==
+ L2ModificationInstruction.L2SubType.VLAN_POP)
+ .findAny();
+
+ assert vlanInstruction.isPresent();
+
+ //check match criteria
+ TrafficSelector selector = fwd.selector();
+ assert selector.getCriterion(Criterion.Type.IN_PORT) != null;
+ assert selector.getCriterion(Criterion.Type.VLAN_VID) != null;
+
+ if (!upstream) {
+ assert selector.getCriterion(Criterion.Type.METADATA) != null;
+ }
+ }
+
+ private class MockOltMeterService implements org.opencord.olt.internalapi.AccessDeviceMeterService {
+ @Override
+ public ImmutableMap<String, Set<MeterKey>> getBpMeterMappings() {
+ return null;
+ }
+
+ @Override
+ public void addMeterIdToBpMapping(DeviceId deviceId, MeterId meterId, String bandwidthProfile) {
+
+ }
+
+ @Override
+ public MeterId getMeterIdFromBpMapping(DeviceId deviceId, String bandwidthProfile) {
+ return null;
+ }
+
+
+ @Override
+ public ImmutableSet<MeterKey> getProgMeters() {
+ return null;
+ }
+
+ @Override
+ public MeterId createMeter(DeviceId deviceId, BandwidthProfileInformation bpInfo,
+ CompletableFuture<Object> meterFuture) {
+ return usMeterId;
+ }
+ }
+
+ private class MockOltFlowObjectiveService implements org.onosproject.net.flowobjective.FlowObjectiveService {
+ @Override
+ public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
+
+ EthTypeCriterion ethType = (EthTypeCriterion)
+ filterForCriterion(filteringObjective.conditions(), Criterion.Type.ETH_TYPE);
+
+ Instructions.MeterInstruction meter = filteringObjective.meta().metered();
+ Instruction writeMetadata = filteringObjective.meta().writeMetadata();
+ VlanIdCriterion vlanIdCriterion = (VlanIdCriterion)
+ filterForCriterion(filteringObjective.conditions(), Criterion.Type.VLAN_VID);
+ PortCriterion portCriterion = (PortCriterion) filteringObjective.key();
+
+
+ if (ethType.ethType().equals(EthType.EtherType.LLDP.ethType()) ||
+ portCriterion.port().equals(nniPortNumber)) {
+ assert meter == null;
+ assert writeMetadata == null;
+ assert vlanIdCriterion == null;
+ } else {
+ assert meter.meterId().equals(usMeterId) || meter.meterId().equals(dsMeterId);
+ assert writeMetadata != null;
+ assert vlanIdCriterion.vlanId() == uniTagInfo.getPonCTag();
+ }
+
+ }
+
+ @Override
+ public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
+
+ }
+
+ @Override
+ public void next(DeviceId deviceId, NextObjective nextObjective) {
+
+ }
+
+ @Override
+ public int allocateNextId() {
+ return 0;
+ }
+
+ @Override
+ public void initPolicy(String s) {
+
+ }
+
+ @Override
+ public void apply(DeviceId deviceId, Objective objective) {
+
+ }
+
+ @Override
+ public Map<Pair<Integer, DeviceId>, List<String>> getNextMappingsChain() {
+ return null;
+ }
+
+ @Override
+ public List<String> getNextMappings() {
+ return null;
+ }
+
+ @Override
+ public List<String> getPendingFlowObjectives() {
+ return null;
+ }
+
+ @Override
+ public ListMultimap<FilteringObjQueueKey, Objective> getFilteringObjQueue() {
+ return null;
+ }
+
+ @Override
+ public ListMultimap<ForwardingObjQueueKey, Objective> getForwardingObjQueue() {
+ return null;
+ }
+
+ @Override
+ public ListMultimap<NextObjQueueKey, Objective> getNextObjQueue() {
+ return null;
+ }
+
+ @Override
+ public Map<FilteringObjQueueKey, Objective> getFilteringObjQueueHead() {
+ return null;
+ }
+
+ @Override
+ public Map<ForwardingObjQueueKey, Objective> getForwardingObjQueueHead() {
+ return null;
+ }
+
+ @Override
+ public Map<NextObjQueueKey, Objective> getNextObjQueueHead() {
+ return null;
+ }
+
+ @Override
+ public void clearQueue() {
+
+ }
+
+ private Criterion filterForCriterion(Collection<Criterion> criteria, Criterion.Type type) {
+ return criteria.stream()
+ .filter(c -> c.type().equals(type))
+ .limit(1)
+ .findFirst().orElse(null);
+ }
+ }
+
+ private class MockMastershipService implements org.onosproject.mastership.MastershipService {
+ @Override
+ public MastershipRole getLocalRole(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public boolean isLocalMaster(DeviceId deviceId) {
+ return true;
+ }
+
+ @Override
+ public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public NodeId getMasterFor(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public RoleInfo getNodesFor(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public MastershipInfo getMastershipFor(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public Set<DeviceId> getDevicesOf(NodeId nodeId) {
+ return null;
+ }
+
+ @Override
+ public void addListener(MastershipListener mastershipListener) {
+
+ }
+
+ @Override
+ public void removeListener(MastershipListener mastershipListener) {
+
+ }
+ }
+}
diff --git a/app/src/test/java/org/opencord/olt/impl/OltMeterTest.java b/app/src/test/java/org/opencord/olt/impl/OltMeterTest.java
new file mode 100644
index 0000000..7100b0f
--- /dev/null
+++ b/app/src/test/java/org/opencord/olt/impl/OltMeterTest.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.olt.impl;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.meter.DefaultMeter;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterId;
+import org.onosproject.net.meter.MeterKey;
+import org.onosproject.net.meter.MeterListener;
+import org.onosproject.net.meter.MeterRequest;
+import org.opencord.sadis.BandwidthProfileInformation;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+public class OltMeterTest extends TestBase {
+ private OltMeterService oltMeterService;
+
+ private BandwidthProfileInformation bandwidthProfileInformation = new BandwidthProfileInformation();
+
+ @Before
+ public void setUp() {
+ oltMeterService = new OltMeterService();
+ oltMeterService.bpInfoToMeter = Maps.newConcurrentMap();
+ oltMeterService.programmedMeters = Sets.newConcurrentHashSet();
+ oltMeterService.meterService = new MockMeterService();
+ }
+
+ @Test
+ public void testAddAndGetMeterIdToBpMapping() {
+ oltMeterService.addMeterIdToBpMapping(DEVICE_ID_1, usMeterId, usBpId);
+ MeterId usMeterId = oltMeterService.getMeterIdFromBpMapping(DEVICE_ID_1, usBpId);
+ assert usMeterId.equals(this.usMeterId);
+
+ oltMeterService.addMeterIdToBpMapping(DEVICE_ID_1, dsMeterId, dsBpId);
+ MeterId dsMeterId = oltMeterService.getMeterIdFromBpMapping(DEVICE_ID_1, dsBpId);
+ assert dsMeterId.equals(this.dsMeterId);
+
+ ImmutableMap<String, Set<MeterKey>> meterMappings = oltMeterService.getBpMeterMappings();
+ assert meterMappings.size() == 2;
+ }
+
+ @Test
+ public void testCreateMeter() {
+ //with provided bandwidth profile information
+ bandwidthProfileInformation.setId(usBpId);
+ bandwidthProfileInformation.setExceededInformationRate(10000);
+ bandwidthProfileInformation.setExceededBurstSize(10000L);
+ bandwidthProfileInformation.setCommittedBurstSize(10000L);
+ bandwidthProfileInformation.setCommittedInformationRate(10000);
+
+ oltMeterService.addMeterIdToBpMapping(DEVICE_ID_1, usMeterId, usBpId);
+
+
+ MeterId meterId =
+ oltMeterService.createMeter(DEVICE_ID_1, bandwidthProfileInformation, new CompletableFuture<>());
+ assert meterId != null;
+
+ //with null bandwidth profile information
+ meterId = oltMeterService.createMeter(DEVICE_ID_1, null, new CompletableFuture<>());
+ assert meterId == null;
+ }
+
+
+ private class MockMeterService implements org.onosproject.net.meter.MeterService {
+ @Override
+ public Meter submit(MeterRequest meterRequest) {
+ return DefaultMeter.builder()
+ .forDevice(DEVICE_ID_1)
+ .fromApp(appId)
+ .withId(usMeterId)
+ .build();
+ }
+
+ @Override
+ public void withdraw(MeterRequest meterRequest, MeterId meterId) {
+
+ }
+
+ @Override
+ public Meter getMeter(DeviceId deviceId, MeterId meterId) {
+ return null;
+ }
+
+ @Override
+ public Collection<Meter> getAllMeters() {
+ return null;
+ }
+
+ @Override
+ public Collection<Meter> getMeters(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public MeterId allocateMeterId(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public void freeMeterId(DeviceId deviceId, MeterId meterId) {
+
+ }
+
+ @Override
+ public void addListener(MeterListener meterListener) {
+
+ }
+
+ @Override
+ public void removeListener(MeterListener meterListener) {
+
+ }
+ }
+}
diff --git a/app/src/test/java/org/opencord/olt/impl/OltTest.java b/app/src/test/java/org/opencord/olt/impl/OltTest.java
index a925aa3..c417590 100644
--- a/app/src/test/java/org/opencord/olt/impl/OltTest.java
+++ b/app/src/test/java/org/opencord/olt/impl/OltTest.java
@@ -18,14 +18,10 @@
import static org.junit.Assert.assertEquals;
import java.util.Set;
-
import org.junit.Before;
import org.junit.Test;
import org.onlab.packet.ChassisId;
-import org.onlab.packet.Ip4Address;
-import org.onlab.packet.MacAddress;
-import org.onlab.packet.VlanId;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
@@ -38,24 +34,15 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.provider.ProviderId;
-import org.opencord.sadis.BandwidthProfileInformation;
-import org.opencord.sadis.BaseInformationService;
import org.opencord.sadis.SubscriberAndDeviceInformation;
-import org.opencord.sadis.SadisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OltTest {
+public class OltTest extends TestBase {
private final Logger log = LoggerFactory.getLogger(getClass());
private Olt olt;
- private static final VlanId CLIENT_C_TAG = VlanId.vlanId((short) 999);
- private static final VlanId CLIENT_S_TAG = VlanId.vlanId((short) 111);
- private static final String CLIENT_NAS_PORT_ID = "PON 1/1";
- private static final String CLIENT_CIRCUIT_ID = "CIR-PON 1/1";
- private static final String OLT_DEV_ID = "of:00000000000000aa";
- private static final DeviceId DEVICE_ID_1 = DeviceId.deviceId(OLT_DEV_ID);
private static final String SCHEME_NAME = "olt";
private static final DefaultAnnotations DEVICE_ANNOTATIONS = DefaultAnnotations.builder()
.set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).build();
@@ -66,7 +53,6 @@
olt.deviceService = new MockDeviceService();
olt.sadisService = new MockSadisService();
olt.subsService = olt.sadisService.getSubscriberInfoService();
-
}
/**
@@ -92,8 +78,6 @@
SubscriberAndDeviceInformation s = olt.getSubscriber(cp);
assertEquals(s.circuitId(), CLIENT_CIRCUIT_ID);
- assertEquals(s.cTag(), CLIENT_C_TAG);
- assertEquals(s.sTag(), CLIENT_S_TAG);
assertEquals(s.nasPortId(), CLIENT_NAS_PORT_ID);
}
@@ -103,7 +87,7 @@
String manufacturer, String hwVersion, String swVersion,
String serialNumber, ChassisId chassisId, Annotations... annotations) {
super(providerId, id, type, manufacturer, hwVersion, swVersion, serialNumber,
- chassisId, annotations);
+ chassisId, annotations);
}
}
@@ -111,8 +95,8 @@
private ProviderId providerId = new ProviderId("of", "foo");
private final Device device1 = new MockDevice(providerId, DEVICE_ID_1, Device.Type.SWITCH,
- "foo.inc", "0", "0", OLT_DEV_ID, new ChassisId(),
- DEVICE_ANNOTATIONS);
+ "foo.inc", "0", "0", OLT_DEV_ID, new ChassisId(),
+ DEVICE_ANNOTATIONS);
@Override
public Device getDevice(DeviceId devId) {
@@ -170,53 +154,8 @@
}
}
- private class MockSadisService implements SadisService {
- @Override
- public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() {
- return new MockSubService();
- }
- @Override
- public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() {
- return null;
- }
- }
-
- private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> {
- MockSubscriberAndDeviceInformation sub =
- new MockSubscriberAndDeviceInformation(CLIENT_NAS_PORT_ID, CLIENT_C_TAG,
- CLIENT_S_TAG, CLIENT_NAS_PORT_ID, CLIENT_CIRCUIT_ID, null, null);
- @Override
- public SubscriberAndDeviceInformation get(String id) {
- return sub;
- }
-
- @Override
- public void invalidateAll() {}
- @Override
- public void invalidateId(String id) {}
- @Override
- public SubscriberAndDeviceInformation getfromCache(String id) {
- return null;
- }
- }
-
- private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation {
-
- MockSubscriberAndDeviceInformation(String id, VlanId ctag,
- VlanId stag, String nasPortId,
- String circuitId, MacAddress hardId,
- Ip4Address ipAddress) {
- this.setCTag(ctag);
- this.setHardwareIdentifier(hardId);
- this.setId(id);
- this.setIPAddress(ipAddress);
- this.setSTag(stag);
- this.setNasPortId(nasPortId);
- this.setCircuitId(circuitId);
- }
- }
}
\ No newline at end of file
diff --git a/app/src/test/java/org/opencord/olt/impl/TestBase.java b/app/src/test/java/org/opencord/olt/impl/TestBase.java
new file mode 100644
index 0000000..b8447a9
--- /dev/null
+++ b/app/src/test/java/org/opencord/olt/impl/TestBase.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2016-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.olt.impl;
+
+import com.google.common.collect.Maps;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.meter.MeterId;
+import org.opencord.sadis.BandwidthProfileInformation;
+import org.opencord.sadis.BaseInformationService;
+import org.opencord.sadis.SadisService;
+import org.opencord.sadis.SubscriberAndDeviceInformation;
+
+import java.util.Map;
+
+public class TestBase {
+
+ protected static final String CLIENT_NAS_PORT_ID = "PON 1/1";
+ protected static final String CLIENT_CIRCUIT_ID = "CIR-PON 1/1";
+ protected static final String OLT_DEV_ID = "of:00000000000000aa";
+ protected static final DeviceId DEVICE_ID_1 = DeviceId.deviceId(OLT_DEV_ID);
+ protected MeterId usMeterId = MeterId.meterId(1);
+ protected MeterId dsMeterId = MeterId.meterId(2);
+ protected String usBpId = "HSIA-US";
+ protected String dsBpId = "HSIA-DS";
+ protected DefaultApplicationId appId = new DefaultApplicationId(1, "OltServices");
+
+ Map<String, BandwidthProfileInformation> bpInformation = Maps.newConcurrentMap();
+
+ protected void addBandwidthProfile(String id) {
+ BandwidthProfileInformation bpInfo = new BandwidthProfileInformation();
+ bpInfo.setAssuredInformationRate(0);
+ bpInfo.setCommittedInformationRate(10000);
+ bpInfo.setCommittedBurstSize(1000L);
+ bpInfo.setExceededBurstSize(2000L);
+ bpInfo.setExceededInformationRate(20000);
+ bpInformation.put(id, bpInfo);
+ }
+
+ protected class MockSadisService implements SadisService {
+
+ @Override
+ public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() {
+ return new MockSubService();
+ }
+
+ @Override
+ public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() {
+ return new MockBpService();
+ }
+ }
+
+ private class MockBpService implements BaseInformationService<BandwidthProfileInformation> {
+
+ @Override
+ public void invalidateAll() {
+
+ }
+
+ @Override
+ public void invalidateId(String id) {
+
+ }
+
+ @Override
+ public BandwidthProfileInformation get(String id) {
+ return bpInformation.get(id);
+ }
+
+ @Override
+ public BandwidthProfileInformation getfromCache(String id) {
+ return null;
+ }
+ }
+
+ private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> {
+ MockSubscriberAndDeviceInformation sub =
+ new MockSubscriberAndDeviceInformation(CLIENT_NAS_PORT_ID,
+ CLIENT_NAS_PORT_ID, CLIENT_CIRCUIT_ID, null, null);
+
+ @Override
+ public SubscriberAndDeviceInformation get(String id) {
+ return sub;
+ }
+
+ @Override
+ public void invalidateAll() {
+ }
+
+ @Override
+ public void invalidateId(String id) {
+ }
+
+ @Override
+ public SubscriberAndDeviceInformation getfromCache(String id) {
+ return null;
+ }
+ }
+
+ private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation {
+
+ MockSubscriberAndDeviceInformation(String id, String nasPortId,
+ String circuitId, MacAddress hardId,
+ Ip4Address ipAddress) {
+ this.setHardwareIdentifier(hardId);
+ this.setId(id);
+ this.setIPAddress(ipAddress);
+ this.setNasPortId(nasPortId);
+ this.setCircuitId(circuitId);
+ }
+ }
+}