blob: 79276366ea33494495ed2e6c149be6e669887c7e [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 Chan6c624992017-08-18 17:11:34 -070019import com.google.common.collect.Sets;
Charles Chan910be6a2017-08-23 14:46:43 -070020import org.onlab.packet.IpAddress;
21import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.VlanId;
24import org.onosproject.routeservice.ResolvedRoute;
25import org.onosproject.routeservice.Route;
Charles Chan6c624992017-08-18 17:11:34 -070026import org.onosproject.routeservice.RouteInfo;
27import org.onosproject.routeservice.RouteServiceAdapter;
28import org.onosproject.routeservice.RouteTableId;
29
30import java.util.Collection;
Charles Chan910be6a2017-08-23 14:46:43 -070031import java.util.Map;
32import java.util.stream.Collectors;
Charles Chan6c624992017-08-18 17:11:34 -070033
34/**
35 * Mock Route Service.
36 * We assume there is only one routing table named "default".
37 */
38public class MockRouteService extends RouteServiceAdapter {
Charles Chan910be6a2017-08-23 14:46:43 -070039 private Map<MockRoutingTableKey, MockRoutingTableValue> routingTable;
Charles Chan6c624992017-08-18 17:11:34 -070040
Charles Chan910be6a2017-08-23 14:46:43 -070041 MockRouteService(Map<MockRoutingTableKey, MockRoutingTableValue> routingTable) {
42 this.routingTable = routingTable;
Charles Chan6c624992017-08-18 17:11:34 -070043 }
44
45 @Override
46 public Collection<RouteInfo> getRoutes(RouteTableId id) {
Charles Chan910be6a2017-08-23 14:46:43 -070047 return routingTable.entrySet().stream().map(e -> {
48 IpPrefix prefix = e.getKey().ipPrefix;
49 IpAddress nextHop = IpAddress.valueOf(0); // dummy
50 MacAddress mac = e.getValue().macAddress;
51 VlanId vlan = e.getValue().vlanId;
52 Route route = new Route(Route.Source.STATIC, prefix, nextHop);
53 ResolvedRoute rr = new ResolvedRoute(route, mac, vlan);
54
55 return new RouteInfo(prefix, rr, Sets.newHashSet(rr));
56 }).collect(Collectors.toSet());
Charles Chan6c624992017-08-18 17:11:34 -070057 }
58
59 @Override
60 public Collection<RouteTableId> getRouteTables() {
61 return Sets.newHashSet(new RouteTableId("default"));
62 }
63}