Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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.drivers.bmv2; |
| 18 | |
| 19 | import org.onosproject.bmv2.model.Bmv2PipelineModelParser; |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame^] | 20 | import org.onosproject.driver.pipeline.DefaultSingleTablePipeline; |
| 21 | import org.onosproject.net.behaviour.Pipeliner; |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 22 | import org.onosproject.net.pi.model.DefaultPiPipeconf; |
| 23 | import org.onosproject.net.pi.model.PiPipeconf; |
| 24 | import org.onosproject.net.pi.model.PiPipeconfId; |
| 25 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
| 26 | |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame^] | 27 | import java.net.URL; |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 28 | |
| 29 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
| 30 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT; |
| 31 | |
| 32 | /** |
| 33 | * Factory of pipeconf implementation for the default.p4 program on BMv2. |
| 34 | */ |
| 35 | final class Bmv2DefaultPipeconfFactory { |
| 36 | |
| 37 | private static final String PIPECONF_ID = "bmv2-default-pipeconf"; |
| 38 | private static final String JSON_PATH = "/default.json"; |
| 39 | private static final String P4INFO_PATH = "/default.p4info"; |
| 40 | |
| 41 | private Bmv2DefaultPipeconfFactory() { |
| 42 | // Hides constructor. |
| 43 | } |
| 44 | |
| 45 | static PiPipeconf get() { |
| 46 | |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame^] | 47 | final URL jsonUrl = Bmv2DefaultPipeconfFactory.class.getResource(JSON_PATH); |
| 48 | final URL p4InfoUrl = Bmv2DefaultPipeconfFactory.class.getResource(P4INFO_PATH); |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 49 | |
| 50 | return DefaultPiPipeconf.builder() |
| 51 | .withId(new PiPipeconfId(PIPECONF_ID)) |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame^] | 52 | .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl)) |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 53 | .addBehaviour(PiPipelineInterpreter.class, Bmv2DefaultInterpreter.class) |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame^] | 54 | .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class) |
| 55 | .addExtension(P4_INFO_TEXT, p4InfoUrl) |
| 56 | .addExtension(BMV2_JSON, jsonUrl) |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 57 | .build(); |
| 58 | } |
| 59 | } |