Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 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; |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 21 | import org.onosproject.drivers.p4runtime.DefaultP4Interpreter; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 22 | import org.onosproject.drivers.p4runtime.DefaultP4PortStatisticsDiscovery; |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame] | 23 | import org.onosproject.net.behaviour.Pipeliner; |
Andrea Campanella | 1909032 | 2017-08-22 10:31:37 +0200 | [diff] [blame] | 24 | import org.onosproject.net.device.PortStatisticsDiscovery; |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 25 | import org.onosproject.net.pi.model.DefaultPiPipeconf; |
| 26 | import org.onosproject.net.pi.model.PiPipeconf; |
| 27 | import org.onosproject.net.pi.model.PiPipeconfId; |
| 28 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
| 29 | |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame] | 30 | import java.net.URL; |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 31 | |
| 32 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
| 33 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT; |
| 34 | |
| 35 | /** |
| 36 | * Factory of pipeconf implementation for the default.p4 program on BMv2. |
| 37 | */ |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 38 | public final class Bmv2DefaultPipeconfFactory { |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 39 | |
| 40 | private static final String PIPECONF_ID = "bmv2-default-pipeconf"; |
| 41 | private static final String JSON_PATH = "/default.json"; |
| 42 | private static final String P4INFO_PATH = "/default.p4info"; |
| 43 | |
Carmelo Cascone | 44daf56 | 2017-07-16 23:55:08 -0400 | [diff] [blame] | 44 | private static final PiPipeconf PIPECONF = buildPipeconf(); |
| 45 | |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 46 | private Bmv2DefaultPipeconfFactory() { |
| 47 | // Hides constructor. |
| 48 | } |
| 49 | |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 50 | public static PiPipeconf get() { |
Carmelo Cascone | 44daf56 | 2017-07-16 23:55:08 -0400 | [diff] [blame] | 51 | return PIPECONF; |
| 52 | } |
| 53 | |
| 54 | private static PiPipeconf buildPipeconf() { |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 55 | |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame] | 56 | final URL jsonUrl = Bmv2DefaultPipeconfFactory.class.getResource(JSON_PATH); |
| 57 | final URL p4InfoUrl = Bmv2DefaultPipeconfFactory.class.getResource(P4INFO_PATH); |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 58 | return DefaultPiPipeconf.builder() |
| 59 | .withId(new PiPipeconfId(PIPECONF_ID)) |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame] | 60 | .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl)) |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 61 | .addBehaviour(PiPipelineInterpreter.class, DefaultP4Interpreter.class) |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame] | 62 | .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class) |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 63 | .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class) |
Carmelo Cascone | 31d3e44 | 2017-07-18 16:58:51 -0400 | [diff] [blame] | 64 | .addExtension(P4_INFO_TEXT, p4InfoUrl) |
| 65 | .addExtension(BMV2_JSON, jsonUrl) |
Carmelo Cascone | 07d7271 | 2017-07-14 15:57:47 -0400 | [diff] [blame] | 66 | .build(); |
| 67 | } |
| 68 | } |