blob: b284eaaa85475ca884947c2bad466837f50b54cb [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.p4tutorial.pipeconf;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.bmv2.model.Bmv2PipelineModelParser;
import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
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 org.onosproject.net.pi.model.PiPipelineModel;
import org.onosproject.net.pi.runtime.PiPipeconfService;
import java.net.URL;
import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.BMV2_JSON;
import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT;
/**
* Component that produces and registers a pipeconf when loaded.
*/
@Component(immediate = true)
public final class PipeconfFactory {
public static final PiPipeconfId PIPECONF_ID = new PiPipeconfId("p4-tutorial-pipeconf");
private static final URL P4INFO_URL = PipeconfFactory.class.getResource("/main.p4info");
private static final URL BMV2_JSON_URL = PipeconfFactory.class.getResource("/main.json");
private static final PiPipelineModel PIPELINE_MODEL = Bmv2PipelineModelParser.parse(BMV2_JSON_URL);
private static final PiPipeconf PIPECONF = DefaultPiPipeconf.builder()
.withId(PIPECONF_ID)
.withPipelineModel(PIPELINE_MODEL)
.addBehaviour(PiPipelineInterpreter.class, PipelineInterpreterImpl.class)
.addBehaviour(PortStatisticsDiscovery.class, PortStatisticsDiscoveryImpl.class)
// Since main.p4 defines only 1 table, we re-use the existing single-table pipeliner.
.addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class)
.addExtension(P4_INFO_TEXT, P4INFO_URL)
.addExtension(BMV2_JSON, BMV2_JSON_URL)
.build();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private PiPipeconfService piPipeconfService;
@Activate
public void activate() {
// Registers the pipeconf at component activation.
piPipeconfService.register(PIPECONF);
}
@Deactivate
public void deactivate() {
piPipeconfService.remove(PIPECONF.id());
}
}