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; |
Carmelo Cascone | 4fc9e74 | 2017-09-06 21:56:57 +0200 | [diff] [blame] | 23 | import org.onosproject.drivers.p4runtime.NetcfgLinkDiscovery; |
| 24 | import org.onosproject.net.behaviour.LinkDiscovery; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 25 | import org.onosproject.net.behaviour.Pipeliner; |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame] | 26 | import org.onosproject.net.device.PortStatisticsDiscovery; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 27 | import org.onosproject.net.pi.model.DefaultPiPipeconf; |
| 28 | import org.onosproject.net.pi.model.PiPipeconf; |
| 29 | import org.onosproject.net.pi.model.PiPipeconfId; |
| 30 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
| 31 | |
| 32 | import java.net.URL; |
| 33 | |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 34 | import static java.lang.String.format; |
| 35 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.*; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Factory of pipeconf implementation for the default.p4 program on Tofino. |
| 39 | */ |
| 40 | final class TofinoDefaultPipeconfFactory { |
| 41 | |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 42 | private static final String PIPECONF_ID_BASE = "tofino-default-%s-pipeconf"; |
| 43 | private static final String JSON_PATH_BASE = "/default-p4/%s/default.json"; |
| 44 | private static final String CONTEXT_JSON_PATH_BASE = "/default-p4/%s/context/context.json"; |
| 45 | private static final String TOFINO_PATH_BASE = "/default-p4/%s/tofino.bin"; |
| 46 | private static final String P4INFO_PATH_BASE = "/default-p4/%s/default.p4info"; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 47 | |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 48 | private static final String MAVERICKS = "mavericks"; |
| 49 | private static final String MONTARA = "montara"; |
| 50 | |
| 51 | private static final PiPipeconf PIPECONF_MAVERICKS = build(MAVERICKS); |
| 52 | private static final PiPipeconf PIPECONF_MONTARA = build(MONTARA); |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 53 | |
| 54 | private TofinoDefaultPipeconfFactory() { |
| 55 | // Hides constructor. |
| 56 | } |
| 57 | |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 58 | static PiPipeconf getMavericks() { |
| 59 | return PIPECONF_MAVERICKS; |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 62 | static PiPipeconf getMontara() { |
| 63 | return PIPECONF_MONTARA; |
| 64 | } |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 65 | |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 66 | private static PiPipeconf build(String system) { |
| 67 | final URL jsonUrl = TofinoDefaultPipeconfFactory.class.getResource(format(JSON_PATH_BASE, system)); |
| 68 | final URL p4InfoUrl = TofinoDefaultPipeconfFactory.class.getResource(format(P4INFO_PATH_BASE, system)); |
| 69 | final URL tofinoUrl = TofinoDefaultPipeconfFactory.class.getResource(format(TOFINO_PATH_BASE, system)); |
| 70 | final URL contextUrl = TofinoDefaultPipeconfFactory.class.getResource(format(CONTEXT_JSON_PATH_BASE, system)); |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 71 | |
| 72 | return DefaultPiPipeconf.builder() |
Carmelo Cascone | 5db3968 | 2017-09-07 16:36:42 +0200 | [diff] [blame^] | 73 | .withId(new PiPipeconfId(format(PIPECONF_ID_BASE, system))) |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 74 | .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl)) |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame] | 75 | .addBehaviour(PiPipelineInterpreter.class, DefaultP4Interpreter.class) |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 76 | .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class) |
Carmelo Cascone | ba74023 | 2017-09-06 21:52:08 +0200 | [diff] [blame] | 77 | .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class) |
Carmelo Cascone | 4fc9e74 | 2017-09-06 21:56:57 +0200 | [diff] [blame] | 78 | // FIXME: remove as soon as we get Packet I/O working |
| 79 | .addBehaviour(LinkDiscovery.class, NetcfgLinkDiscovery.class) |
Andrea Campanella | bf1301d | 2017-08-07 18:33:52 +0200 | [diff] [blame] | 80 | .addExtension(P4_INFO_TEXT, p4InfoUrl) |
| 81 | .addExtension(BMV2_JSON, jsonUrl) |
| 82 | .addExtension(TOFINO_BIN, tofinoUrl) |
| 83 | .addExtension(TOFINO_CONTEXT_JSON, contextUrl) |
| 84 | .build(); |
| 85 | } |
| 86 | } |