blob: 4d222d8da6eda0eefcbb07ed7103252a465dce0b [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
19import org.onlab.packet.IpPrefix;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.PortNumber;
Charles Chan12a8a842020-02-14 13:23:57 -080024import org.onosproject.net.flowobjective.Objective;
Charles Chan6c624992017-08-18 17:11:34 -070025
26import java.util.Map;
Charles Chan12a8a842020-02-14 13:23:57 -080027import java.util.concurrent.CompletableFuture;
Charles Chan6c624992017-08-18 17:11:34 -070028
29/**
30 * Mock Routing Rule Populator.
31 */
32public class MockRoutingRulePopulator extends RoutingRulePopulator {
33 private Map<MockRoutingTableKey, MockRoutingTableValue> routingTable;
34
35 MockRoutingRulePopulator(SegmentRoutingManager srManager,
36 Map<MockRoutingTableKey, MockRoutingTableValue> routingTable) {
37 super(srManager);
38 this.routingTable = routingTable;
39 }
40
41 @Override
Charles Chan12a8a842020-02-14 13:23:57 -080042 public CompletableFuture<Objective> populateRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac,
43 VlanId hostVlanId, PortNumber outPort, boolean directHost) {
Charles Chan6c624992017-08-18 17:11:34 -070044 MockRoutingTableKey rtKey = new MockRoutingTableKey(deviceId, prefix);
45 MockRoutingTableValue rtValue = new MockRoutingTableValue(outPort, hostMac, hostVlanId);
46 routingTable.put(rtKey, rtValue);
Charles Chan12a8a842020-02-14 13:23:57 -080047 return CompletableFuture.completedFuture(null);
Charles Chan6c624992017-08-18 17:11:34 -070048 }
49
50 @Override
Charles Chan12a8a842020-02-14 13:23:57 -080051 public CompletableFuture<Objective> revokeRoute(DeviceId deviceId, IpPrefix prefix,
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +000052 MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, boolean directHost) {
Charles Chan6c624992017-08-18 17:11:34 -070053 MockRoutingTableKey rtKey = new MockRoutingTableKey(deviceId, prefix);
54 MockRoutingTableValue rtValue = new MockRoutingTableValue(outPort, hostMac, hostVlanId);
55 routingTable.remove(rtKey, rtValue);
Charles Chan12a8a842020-02-14 13:23:57 -080056 return CompletableFuture.completedFuture(null);
Charles Chan6c624992017-08-18 17:11:34 -070057 }
Ruchi Sahota71bcb4e2019-01-28 01:08:18 +000058}