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; |
| 20 | import org.onosproject.net.pi.model.DefaultPiPipeconf; |
| 21 | import org.onosproject.net.pi.model.PiPipeconf; |
| 22 | import org.onosproject.net.pi.model.PiPipeconfId; |
| 23 | import org.onosproject.net.pi.model.PiPipelineInterpreter; |
| 24 | |
| 25 | import java.io.InputStream; |
| 26 | |
| 27 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON; |
| 28 | import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT; |
| 29 | |
| 30 | /** |
| 31 | * Factory of pipeconf implementation for the default.p4 program on BMv2. |
| 32 | */ |
| 33 | final class Bmv2DefaultPipeconfFactory { |
| 34 | |
| 35 | private static final String PIPECONF_ID = "bmv2-default-pipeconf"; |
| 36 | private static final String JSON_PATH = "/default.json"; |
| 37 | private static final String P4INFO_PATH = "/default.p4info"; |
| 38 | |
| 39 | private Bmv2DefaultPipeconfFactory() { |
| 40 | // Hides constructor. |
| 41 | } |
| 42 | |
| 43 | static PiPipeconf get() { |
| 44 | |
| 45 | final InputStream jsonConfigStream = Bmv2DefaultPipeconfFactory.class.getResourceAsStream(JSON_PATH); |
| 46 | final InputStream p4InfoStream = Bmv2DefaultPipeconfFactory.class.getResourceAsStream(P4INFO_PATH); |
| 47 | |
| 48 | return DefaultPiPipeconf.builder() |
| 49 | .withId(new PiPipeconfId(PIPECONF_ID)) |
| 50 | .withPipelineModel(Bmv2PipelineModelParser.parse(jsonConfigStream)) |
| 51 | // TODO: reuse default single table pipeliner. |
| 52 | .addBehaviour(PiPipelineInterpreter.class, Bmv2DefaultInterpreter.class) |
| 53 | .addExtension(P4_INFO_TEXT, p4InfoStream) |
| 54 | .addExtension(BMV2_JSON, jsonConfigStream) |
| 55 | .build(); |
| 56 | } |
| 57 | } |