Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
| 17 | package org.onosproject.segmentrouting; |
| 18 | |
Charles Chan | fab6147 | 2021-06-14 23:31:23 -0700 | [diff] [blame] | 19 | import org.onlab.packet.MacAddress; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 20 | import org.onosproject.core.DefaultApplicationId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.PortNumber; |
| 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
| 25 | |
Charles Chan | fab6147 | 2021-06-14 23:31:23 -0700 | [diff] [blame] | 26 | import java.util.List; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 27 | import java.util.Map; |
| 28 | import java.util.concurrent.atomic.AtomicInteger; |
| 29 | |
| 30 | /** |
| 31 | * Mock Segment Routing Manager. |
| 32 | */ |
| 33 | public class MockSegmentRoutingManager extends SegmentRoutingManager { |
| 34 | private Map<Integer, TrafficTreatment> nextTable; |
Charles Chan | fab6147 | 2021-06-14 23:31:23 -0700 | [diff] [blame] | 35 | private Map<DeviceId, MacAddress> routerMacs; |
| 36 | private List<DeviceId> infraDeviceIds; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 37 | private AtomicInteger atomicNextId = new AtomicInteger(); |
| 38 | |
Charles Chan | fab6147 | 2021-06-14 23:31:23 -0700 | [diff] [blame] | 39 | MockSegmentRoutingManager(Map<Integer, TrafficTreatment> nextTable, |
| 40 | Map<DeviceId, MacAddress> routerMacs) { |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 41 | appId = new DefaultApplicationId(1, SegmentRoutingManager.APP_NAME); |
| 42 | this.nextTable = nextTable; |
Charles Chan | fab6147 | 2021-06-14 23:31:23 -0700 | [diff] [blame] | 43 | this.routerMacs = routerMacs; |
| 44 | this.infraDeviceIds = List.of(DeviceId.deviceId("device:1")); |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public int getPortNextObjectiveId(DeviceId deviceId, PortNumber portNum, |
| 49 | TrafficTreatment treatment, |
| 50 | TrafficSelector meta, |
| 51 | boolean createIfMissing) { |
| 52 | int nextId = atomicNextId.incrementAndGet(); |
| 53 | nextTable.put(nextId, treatment); |
| 54 | return nextId; |
| 55 | } |
Charles Chan | fab6147 | 2021-06-14 23:31:23 -0700 | [diff] [blame] | 56 | |
| 57 | @Override |
| 58 | public List<DeviceId> getInfraDeviceIds() { |
| 59 | return List.copyOf(infraDeviceIds); |
| 60 | } |
| 61 | |
| 62 | public void setInfraDeviceIds(List<DeviceId> infraDeviceIds) { |
| 63 | this.infraDeviceIds = infraDeviceIds; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public MacAddress getDeviceMacAddress(DeviceId deviceId) { |
| 68 | return routerMacs.get(deviceId); |
| 69 | } |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 70 | } |