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 | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onlab.packet.VlanId; |
| 24 | import org.onosproject.routeservice.ResolvedRoute; |
| 25 | import org.onosproject.routeservice.Route; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 26 | import org.onosproject.routeservice.RouteInfo; |
| 27 | import org.onosproject.routeservice.RouteServiceAdapter; |
| 28 | import org.onosproject.routeservice.RouteTableId; |
| 29 | |
| 30 | import java.util.Collection; |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 31 | import java.util.Map; |
| 32 | import java.util.stream.Collectors; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Mock Route Service. |
| 36 | * We assume there is only one routing table named "default". |
| 37 | */ |
| 38 | public class MockRouteService extends RouteServiceAdapter { |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 39 | private Map<MockRoutingTableKey, MockRoutingTableValue> routingTable; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 40 | |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 41 | MockRouteService(Map<MockRoutingTableKey, MockRoutingTableValue> routingTable) { |
| 42 | this.routingTable = routingTable; |
Charles Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public Collection<RouteInfo> getRoutes(RouteTableId id) { |
Charles Chan | 910be6a | 2017-08-23 14:46:43 -0700 | [diff] [blame] | 47 | 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 Chan | 6c62499 | 2017-08-18 17:11:34 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public Collection<RouteTableId> getRouteTables() { |
| 61 | return Sets.newHashSet(new RouteTableId("default")); |
| 62 | } |
| 63 | } |