blob: 4903c3ec60aa8595e4601f697ee2b5692e6b332d [file] [log] [blame]
Carmelo Cascone07d72712017-07-14 15:57:47 -04001/*
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
17package org.onosproject.drivers.bmv2;
18
19import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
20import org.onosproject.net.pi.model.DefaultPiPipeconf;
21import org.onosproject.net.pi.model.PiPipeconf;
22import org.onosproject.net.pi.model.PiPipeconfId;
23import org.onosproject.net.pi.model.PiPipelineInterpreter;
24
25import java.io.InputStream;
26
27import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
28import 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 */
33final 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}