blob: e60b54cb1d49dd716271b7fa94a71514fc2c93ab [file] [log] [blame]
/*
* Copyright 2017-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.drivers.barefoot;
import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
import org.onosproject.drivers.p4runtime.DefaultP4Interpreter;
import org.onosproject.drivers.p4runtime.DefaultP4PortStatisticsDiscovery;
import org.onosproject.drivers.p4runtime.NetcfgLinkDiscovery;
import org.onosproject.net.behaviour.LinkDiscovery;
import org.onosproject.net.behaviour.Pipeliner;
import org.onosproject.net.device.PortStatisticsDiscovery;
import org.onosproject.net.pi.model.DefaultPiPipeconf;
import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipeconfId;
import org.onosproject.net.pi.model.PiPipelineInterpreter;
import java.net.URL;
import static java.lang.String.format;
import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.*;
/**
* Factory of pipeconf implementation for the default.p4 program on Tofino.
*/
final class TofinoDefaultPipeconfFactory {
private static final String PIPECONF_ID_BASE = "tofino-default-%s-pipeconf";
private static final String JSON_PATH_BASE = "/default-p4/%s/default.json";
private static final String CONTEXT_JSON_PATH_BASE = "/default-p4/%s/context/context.json";
private static final String TOFINO_PATH_BASE = "/default-p4/%s/tofino.bin";
private static final String P4INFO_PATH_BASE = "/default-p4/%s/default.p4info";
private static final String MAVERICKS = "mavericks";
private static final String MONTARA = "montara";
private static final PiPipeconf PIPECONF_MAVERICKS = build(MAVERICKS);
private static final PiPipeconf PIPECONF_MONTARA = build(MONTARA);
private TofinoDefaultPipeconfFactory() {
// Hides constructor.
}
static PiPipeconf getMavericks() {
return PIPECONF_MAVERICKS;
}
static PiPipeconf getMontara() {
return PIPECONF_MONTARA;
}
private static PiPipeconf build(String system) {
final URL jsonUrl = TofinoDefaultPipeconfFactory.class.getResource(format(JSON_PATH_BASE, system));
final URL p4InfoUrl = TofinoDefaultPipeconfFactory.class.getResource(format(P4INFO_PATH_BASE, system));
final URL tofinoUrl = TofinoDefaultPipeconfFactory.class.getResource(format(TOFINO_PATH_BASE, system));
final URL contextUrl = TofinoDefaultPipeconfFactory.class.getResource(format(CONTEXT_JSON_PATH_BASE, system));
return DefaultPiPipeconf.builder()
.withId(new PiPipeconfId(format(PIPECONF_ID_BASE, system)))
.withPipelineModel(Bmv2PipelineModelParser.parse(jsonUrl))
.addBehaviour(PiPipelineInterpreter.class, DefaultP4Interpreter.class)
.addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
.addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class)
// FIXME: remove as soon as we get Packet I/O working
.addBehaviour(LinkDiscovery.class, NetcfgLinkDiscovery.class)
.addExtension(P4_INFO_TEXT, p4InfoUrl)
.addExtension(BMV2_JSON, jsonUrl)
.addExtension(TOFINO_BIN, tofinoUrl)
.addExtension(TOFINO_CONTEXT_JSON, contextUrl)
.build();
}
}