blob: e60b54cb1d49dd716271b7fa94a71514fc2c93ab [file] [log] [blame]
Andrea Campanellabf1301d2017-08-07 18:33:52 +02001/*
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
17package org.onosproject.drivers.barefoot;
18
19import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
20import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
Carmelo Casconeba740232017-09-06 21:52:08 +020021import org.onosproject.drivers.p4runtime.DefaultP4Interpreter;
22import org.onosproject.drivers.p4runtime.DefaultP4PortStatisticsDiscovery;
Carmelo Cascone4fc9e742017-09-06 21:56:57 +020023import org.onosproject.drivers.p4runtime.NetcfgLinkDiscovery;
24import org.onosproject.net.behaviour.LinkDiscovery;
Andrea Campanellabf1301d2017-08-07 18:33:52 +020025import org.onosproject.net.behaviour.Pipeliner;
Carmelo Casconeba740232017-09-06 21:52:08 +020026import org.onosproject.net.device.PortStatisticsDiscovery;
Andrea Campanellabf1301d2017-08-07 18:33:52 +020027import org.onosproject.net.pi.model.DefaultPiPipeconf;
28import org.onosproject.net.pi.model.PiPipeconf;
29import org.onosproject.net.pi.model.PiPipeconfId;
30import org.onosproject.net.pi.model.PiPipelineInterpreter;
31
32import java.net.URL;
33
Carmelo Cascone5db39682017-09-07 16:36:42 +020034import static java.lang.String.format;
35import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.*;
Andrea Campanellabf1301d2017-08-07 18:33:52 +020036
37/**
38 * Factory of pipeconf implementation for the default.p4 program on Tofino.
39 */
40final class TofinoDefaultPipeconfFactory {
41
Carmelo Cascone5db39682017-09-07 16:36:42 +020042 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 Campanellabf1301d2017-08-07 18:33:52 +020047
Carmelo Cascone5db39682017-09-07 16:36:42 +020048 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 Campanellabf1301d2017-08-07 18:33:52 +020053
54 private TofinoDefaultPipeconfFactory() {
55 // Hides constructor.
56 }
57
Carmelo Cascone5db39682017-09-07 16:36:42 +020058 static PiPipeconf getMavericks() {
59 return PIPECONF_MAVERICKS;
Andrea Campanellabf1301d2017-08-07 18:33:52 +020060 }
61
Carmelo Cascone5db39682017-09-07 16:36:42 +020062 static PiPipeconf getMontara() {
63 return PIPECONF_MONTARA;
64 }
Andrea Campanellabf1301d2017-08-07 18:33:52 +020065
Carmelo Cascone5db39682017-09-07 16:36:42 +020066 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 Campanellabf1301d2017-08-07 18:33:52 +020071
72 return DefaultPiPipeconf.builder()
Carmelo Cascone5db39682017-09-07 16:36:42 +020073 .withId(new PiPipeconfId(format(PIPECONF_ID_BASE, system)))
Andrea Campanellabf1301d2017-08-07 18:33:52 +020074 .withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl))
Carmelo Casconeba740232017-09-06 21:52:08 +020075 .addBehaviour(PiPipelineInterpreter.class, DefaultP4Interpreter.class)
Andrea Campanellabf1301d2017-08-07 18:33:52 +020076 .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
Carmelo Casconeba740232017-09-06 21:52:08 +020077 .addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class)
Carmelo Cascone4fc9e742017-09-06 21:56:57 +020078 // FIXME: remove as soon as we get Packet I/O working
79 .addBehaviour(LinkDiscovery.class, NetcfgLinkDiscovery.class)
Andrea Campanellabf1301d2017-08-07 18:33:52 +020080 .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}