Gamze Abaka | 1b7816e | 2019-11-25 06:38:41 +0000 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.olt.impl; |
| 17 | |
| 18 | import com.google.common.collect.Maps; |
| 19 | import org.onlab.packet.Ip4Address; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onosproject.core.DefaultApplicationId; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.meter.MeterId; |
| 24 | import org.opencord.sadis.BandwidthProfileInformation; |
| 25 | import org.opencord.sadis.BaseInformationService; |
| 26 | import org.opencord.sadis.SadisService; |
| 27 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 28 | |
| 29 | import java.util.Map; |
| 30 | |
| 31 | public class TestBase { |
| 32 | |
| 33 | protected static final String CLIENT_NAS_PORT_ID = "PON 1/1"; |
| 34 | protected static final String CLIENT_CIRCUIT_ID = "CIR-PON 1/1"; |
| 35 | protected static final String OLT_DEV_ID = "of:00000000000000aa"; |
| 36 | protected static final DeviceId DEVICE_ID_1 = DeviceId.deviceId(OLT_DEV_ID); |
| 37 | protected MeterId usMeterId = MeterId.meterId(1); |
| 38 | protected MeterId dsMeterId = MeterId.meterId(2); |
| 39 | protected String usBpId = "HSIA-US"; |
| 40 | protected String dsBpId = "HSIA-DS"; |
| 41 | protected DefaultApplicationId appId = new DefaultApplicationId(1, "OltServices"); |
| 42 | |
| 43 | Map<String, BandwidthProfileInformation> bpInformation = Maps.newConcurrentMap(); |
| 44 | |
| 45 | protected void addBandwidthProfile(String id) { |
| 46 | BandwidthProfileInformation bpInfo = new BandwidthProfileInformation(); |
| 47 | bpInfo.setAssuredInformationRate(0); |
| 48 | bpInfo.setCommittedInformationRate(10000); |
| 49 | bpInfo.setCommittedBurstSize(1000L); |
| 50 | bpInfo.setExceededBurstSize(2000L); |
| 51 | bpInfo.setExceededInformationRate(20000); |
| 52 | bpInformation.put(id, bpInfo); |
| 53 | } |
| 54 | |
| 55 | protected class MockSadisService implements SadisService { |
| 56 | |
| 57 | @Override |
| 58 | public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() { |
| 59 | return new MockSubService(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() { |
| 64 | return new MockBpService(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | private class MockBpService implements BaseInformationService<BandwidthProfileInformation> { |
| 69 | |
| 70 | @Override |
| 71 | public void invalidateAll() { |
| 72 | |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void invalidateId(String id) { |
| 77 | |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public BandwidthProfileInformation get(String id) { |
| 82 | return bpInformation.get(id); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public BandwidthProfileInformation getfromCache(String id) { |
| 87 | return null; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> { |
| 92 | MockSubscriberAndDeviceInformation sub = |
| 93 | new MockSubscriberAndDeviceInformation(CLIENT_NAS_PORT_ID, |
| 94 | CLIENT_NAS_PORT_ID, CLIENT_CIRCUIT_ID, null, null); |
| 95 | |
| 96 | @Override |
| 97 | public SubscriberAndDeviceInformation get(String id) { |
| 98 | return sub; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void invalidateAll() { |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void invalidateId(String id) { |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public SubscriberAndDeviceInformation getfromCache(String id) { |
| 111 | return null; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation { |
| 116 | |
| 117 | MockSubscriberAndDeviceInformation(String id, String nasPortId, |
| 118 | String circuitId, MacAddress hardId, |
| 119 | Ip4Address ipAddress) { |
| 120 | this.setHardwareIdentifier(hardId); |
| 121 | this.setId(id); |
| 122 | this.setIPAddress(ipAddress); |
| 123 | this.setNasPortId(nasPortId); |
| 124 | this.setCircuitId(circuitId); |
| 125 | } |
| 126 | } |
| 127 | } |