blob: 18f33c13b340ec1bd659caaeb9f8ba088baa3c3a [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.pi.demo.app.ecmp;
import com.google.common.collect.Lists;
import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
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 java.util.Collection;
import static java.lang.String.format;
import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.*;
final class EcmpPipeconfFactory {
private static final String BMV2_PIPECONF_ID = "bmv2-ecmp";
private static final URL BMV2_P4INFO_URL = EcmpFabricApp.class.getResource("/ecmp_14.p4info");
private static final URL BMV2_JSON_URL = EcmpFabricApp.class.getResource("/ecmp_14.json");
private static final String TOFINO_PIPECONF_ID_BASE = "tofino-ecmp-%s";
private static final String TOFINO_JSON_PATH_BASE = "/ecmp-tofino/%s/ecmp.json";
private static final String TOFINO_P4INFO_PATH_BASE = "/ecmp-tofino/%s/ecmp.p4info";
private static final String TOFINO_CONTEXT_JSON_PATH_BASE = "/ecmp-tofino/%s/context/context.json";
private static final String TOFINO_BIN_PATH_BASE = "/ecmp-tofino/%s/tofino.bin";
private static final String MAVERICKS = "mavericks";
private static final String MONTARA = "montara";
private static final PiPipeconf BMV2_PIPECONF = buildBmv2Pipeconf();
private static final PiPipeconf MAVERICKS_PIPECONF = buildTofinoPipeconf(MAVERICKS);
private static final PiPipeconf MONTARA_PIPECONF = buildTofinoPipeconf(MONTARA);
private EcmpPipeconfFactory() {
// Hides constructor.
}
static Collection<PiPipeconf> getAll() {
return Lists.newArrayList(BMV2_PIPECONF, MAVERICKS_PIPECONF, MONTARA_PIPECONF);
}
private static PiPipeconf buildTofinoPipeconf(String system) {
final URL bmv2JsonUrl = EcmpPipeconfFactory.class.getResource(format(TOFINO_JSON_PATH_BASE, system));
final URL p4InfoUrl = EcmpPipeconfFactory.class.getResource(format(TOFINO_P4INFO_PATH_BASE, system));
final URL tofinoUrl = EcmpPipeconfFactory.class.getResource(format(TOFINO_BIN_PATH_BASE, system));
final URL contextUrl = EcmpPipeconfFactory.class.getResource(format(TOFINO_CONTEXT_JSON_PATH_BASE, system));
return DefaultPiPipeconf.builder()
.withId(new PiPipeconfId(format(TOFINO_PIPECONF_ID_BASE, system)))
.withPipelineModel(Bmv2PipelineModelParser.parse(bmv2JsonUrl))
.addBehaviour(PiPipelineInterpreter.class, EcmpInterpreter.class)
.addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
.addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class)
// FIXME: can remove if Packet I/O is working
.addBehaviour(LinkDiscovery.class, NetcfgLinkDiscovery.class)
.addExtension(P4_INFO_TEXT, p4InfoUrl)
.addExtension(TOFINO_BIN, tofinoUrl)
.addExtension(TOFINO_CONTEXT_JSON, contextUrl)
.build();
}
private static PiPipeconf buildBmv2Pipeconf() {
return DefaultPiPipeconf.builder()
.withId(new PiPipeconfId(BMV2_PIPECONF_ID))
.withPipelineModel(Bmv2PipelineModelParser.parse(BMV2_JSON_URL))
.addBehaviour(PiPipelineInterpreter.class, EcmpInterpreter.class)
.addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
.addBehaviour(PortStatisticsDiscovery.class, DefaultP4PortStatisticsDiscovery.class)
// FIXME: can remove if Packet I/O is working
.addBehaviour(LinkDiscovery.class, NetcfgLinkDiscovery.class)
.addExtension(P4_INFO_TEXT, BMV2_P4INFO_URL)
.addExtension(BMV2_JSON, BMV2_JSON_URL)
.build();
}
}