blob: fdd3951a3f11f42cabec6aa4ad749c515e69cfc3 [file] [log] [blame]
Charles Chan6c624992017-08-18 17:11:34 -07001/*
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
17package org.onosproject.segmentrouting;
18
Charles Chanfab61472021-06-14 23:31:23 -070019import org.onlab.packet.MacAddress;
Charles Chan6c624992017-08-18 17:11:34 -070020import org.onosproject.core.DefaultApplicationId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.PortNumber;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
25
Charles Chanfab61472021-06-14 23:31:23 -070026import java.util.List;
Charles Chan6c624992017-08-18 17:11:34 -070027import java.util.Map;
28import java.util.concurrent.atomic.AtomicInteger;
29
30/**
31 * Mock Segment Routing Manager.
32 */
33public class MockSegmentRoutingManager extends SegmentRoutingManager {
34 private Map<Integer, TrafficTreatment> nextTable;
Charles Chanfab61472021-06-14 23:31:23 -070035 private Map<DeviceId, MacAddress> routerMacs;
36 private List<DeviceId> infraDeviceIds;
Charles Chan6c624992017-08-18 17:11:34 -070037 private AtomicInteger atomicNextId = new AtomicInteger();
38
Charles Chanfab61472021-06-14 23:31:23 -070039 MockSegmentRoutingManager(Map<Integer, TrafficTreatment> nextTable,
40 Map<DeviceId, MacAddress> routerMacs) {
Charles Chan6c624992017-08-18 17:11:34 -070041 appId = new DefaultApplicationId(1, SegmentRoutingManager.APP_NAME);
42 this.nextTable = nextTable;
Charles Chanfab61472021-06-14 23:31:23 -070043 this.routerMacs = routerMacs;
44 this.infraDeviceIds = List.of(DeviceId.deviceId("device:1"));
Charles Chan6c624992017-08-18 17:11:34 -070045 }
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 Chanfab61472021-06-14 23:31:23 -070056
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 Chan6c624992017-08-18 17:11:34 -070070}