blob: 30046279d22f520c73a40e69ff99f4b1a923ce85 [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;
Carmelo Cascone31d3e442017-07-18 16:58:51 -040020import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
21import org.onosproject.net.behaviour.Pipeliner;
Carmelo Cascone07d72712017-07-14 15:57:47 -040022import org.onosproject.net.pi.model.DefaultPiPipeconf;
23import org.onosproject.net.pi.model.PiPipeconf;
24import org.onosproject.net.pi.model.PiPipeconfId;
25import org.onosproject.net.pi.model.PiPipelineInterpreter;
26
Carmelo Cascone31d3e442017-07-18 16:58:51 -040027import java.net.URL;
Carmelo Cascone07d72712017-07-14 15:57:47 -040028
29import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
30import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT;
31
32/**
33 * Factory of pipeconf implementation for the default.p4 program on BMv2.
34 */
35final class Bmv2DefaultPipeconfFactory {
36
37 private static final String PIPECONF_ID = "bmv2-default-pipeconf";
38 private static final String JSON_PATH = "/default.json";
39 private static final String P4INFO_PATH = "/default.p4info";
40
41 private Bmv2DefaultPipeconfFactory() {
42 // Hides constructor.
43 }
44
45 static PiPipeconf get() {
46
Carmelo Cascone31d3e442017-07-18 16:58:51 -040047 final URL jsonUrl = Bmv2DefaultPipeconfFactory.class.getResource(JSON_PATH);
48 final URL p4InfoUrl = Bmv2DefaultPipeconfFactory.class.getResource(P4INFO_PATH);
Carmelo Cascone07d72712017-07-14 15:57:47 -040049
50 return DefaultPiPipeconf.builder()
51 .withId(new PiPipeconfId(PIPECONF_ID))
Carmelo Cascone31d3e442017-07-18 16:58:51 -040052 .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl))
Carmelo Cascone07d72712017-07-14 15:57:47 -040053 .addBehaviour(PiPipelineInterpreter.class, Bmv2DefaultInterpreter.class)
Carmelo Cascone31d3e442017-07-18 16:58:51 -040054 .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
55 .addExtension(P4_INFO_TEXT, p4InfoUrl)
56 .addExtension(BMV2_JSON, jsonUrl)
Carmelo Cascone07d72712017-07-14 15:57:47 -040057 .build();
58 }
59}