Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +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.drivers.barefoot; |
| 18 | |
| 19 | import org.onosproject.bmv2.model.Bmv2PipelineModelParser; |
| 20 | import org.onosproject.driver.pipeline.DefaultSingleTablePipeline; |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame^] | 21 | import org.onosproject.drivers.p4runtime.DefaultP4Interpreter; |
| 22 | import org.onosproject.drivers.p4runtime.DefaultP4PortStatisticsDiscovery; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 23 | import org.onosproject.net.behaviour.Pipeliner; |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame^] | 24 | import org.onosproject.net.device.PortStatisticsDiscovery; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [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 | |
| 30 | import java.net.URL; |
| 31 | |
| 32 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
| 33 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.TOFINO_CONTEXT_JSON; |
| 34 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT; |
| 35 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.TOFINO_BIN; |
| 36 | |
| 37 | /** |
| 38 | * Factory of pipeconf implementation for the default.p4 program on Tofino. |
| 39 | */ |
| 40 | final class TofinoDefaultPipeconfFactory { |
| 41 | |
| 42 | private static final String PIPECONF_ID = "tofino-default-pipeconf"; |
| 43 | private static final String JSON_PATH = "/default.json"; |
| 44 | private static final String CONTEXT_JSON_PATH = "/context.json"; |
| 45 | private static final String TOFINO_PATH = "/tofino.bin"; |
| 46 | private static final String P4INFO_PATH = "/default.p4info"; |
| 47 | |
| 48 | private static final PiPipeconf PIPECONF = buildPipeconf(); |
| 49 | |
| 50 | private TofinoDefaultPipeconfFactory() { |
| 51 | // Hides constructor. |
| 52 | } |
| 53 | |
| 54 | static PiPipeconf get() { |
| 55 | return PIPECONF; |
| 56 | } |
| 57 | |
| 58 | private static PiPipeconf buildPipeconf() { |
| 59 | |
| 60 | final URL jsonUrl = TofinoDefaultPipeconfFactory.class.getResource(JSON_PATH); |
| 61 | final URL p4InfoUrl = TofinoDefaultPipeconfFactory.class.getResource(P4INFO_PATH); |
| 62 | final URL tofinoUrl = TofinoDefaultPipeconfFactory.class.getResource(TOFINO_PATH); |
| 63 | final URL contextUrl = TofinoDefaultPipeconfFactory.class.getResource(CONTEXT_JSON_PATH); |
| 64 | |
| 65 | return DefaultPiPipeconf.builder() |
| 66 | .withId(new PiPipeconfId(PIPECONF_ID)) |
| 67 | .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl)) |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame^] | 68 | .addBehaviour(PiPipelineInterpreter.class, DefaultP4Interpreter.class) |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 69 | .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class) |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame^] | 70 | .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class) |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 71 | .addExtension(P4_INFO_TEXT, p4InfoUrl) |
| 72 | .addExtension(BMV2_JSON, jsonUrl) |
| 73 | .addExtension(TOFINO_BIN, tofinoUrl) |
| 74 | .addExtension(TOFINO_CONTEXT_JSON, contextUrl) |
| 75 | .build(); |
| 76 | } |
| 77 | } |