Carmelo Cascone | 6e85404 | 2017-09-11 21:37:53 +0200 | [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.pi.demo.app.ecmp; |
| 18 | |
| 19 | import org.onosproject.bmv2.model.Bmv2PipelineModelParser; |
| 20 | import org.onosproject.driver.pipeline.DefaultSingleTablePipeline; |
| 21 | import org.onosproject.drivers.p4runtime.DefaultP4PortStatisticsDiscovery; |
| 22 | import org.onosproject.net.behaviour.Pipeliner; |
| 23 | import org.onosproject.net.device.PortStatisticsDiscovery; |
| 24 | import org.onosproject.net.pi.model.DefaultPiPipeconf; |
| 25 | import org.onosproject.net.pi.model.PiPipeconf; |
| 26 | import org.onosproject.net.pi.model.PiPipeconfId; |
| 27 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
| 28 | |
| 29 | import java.net.URL; |
| 30 | import java.util.Collection; |
| 31 | import java.util.Collections; |
| 32 | |
| 33 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
| 34 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT; |
| 35 | |
| 36 | final class EcmpPipeconfFactory { |
| 37 | |
| 38 | private static final String BMV2_PIPECONF_ID = "pi-demo-ecmp"; |
| 39 | private static final URL BMV2_P4INFO_URL = EcmpFabricApp.class.getResource("/ecmp.p4info"); |
| 40 | private static final URL BMV2_JSON_URL = EcmpFabricApp.class.getResource("/ecmp.json"); |
| 41 | |
| 42 | private static final PiPipeconf BMV2_PIPECONF = buildBmv2Pipeconf(); |
| 43 | |
| 44 | private EcmpPipeconfFactory() { |
| 45 | // Hides constructor. |
| 46 | } |
| 47 | |
| 48 | static Collection<PiPipeconf> getAll() { |
| 49 | return Collections.singleton(BMV2_PIPECONF); |
| 50 | } |
| 51 | |
| 52 | private static PiPipeconf buildBmv2Pipeconf() { |
| 53 | return DefaultPiPipeconf.builder() |
| 54 | .withId(new PiPipeconfId(BMV2_PIPECONF_ID)) |
| 55 | .withPipelineModel(Bmv2PipelineModelParser.parse(BMV2_JSON_URL)) |
| 56 | .addBehaviour(PiPipelineInterpreter.class, EcmpInterpreter.class) |
| 57 | .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class) |
| 58 | .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class) |
| 59 | .addExtension(P4_INFO_TEXT, BMV2_P4INFO_URL) |
| 60 | .addExtension(BMV2_JSON, BMV2_JSON_URL) |
| 61 | .build(); |
| 62 | } |
| 63 | } |