blob: 7d1ee4e3068a01f14c401d2f1c856dcad0f85888 [file] [log] [blame]
Carmelo Cascone356ab8b2019-09-25 01:02:53 -07001/*
2 * Copyright 2019-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.pipelines.fabric.impl;
18
Carmelo Casconeb330fc72020-07-17 15:27:02 -070019import org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable;
Daniele Moro464e5ed2019-07-25 14:45:01 -070020
21import org.onosproject.net.behaviour.BngProgrammable;
Daniele Moro7c31a3b2021-06-15 20:53:22 +020022import org.onosproject.net.behaviour.upf.UpfProgrammable;
23import org.onosproject.pipelines.fabric.impl.behaviour.upf.FabricUpfProgrammable;
Carmelo Cascone356ab8b2019-09-25 01:02:53 -070024import org.onosproject.net.behaviour.Pipeliner;
25import org.onosproject.net.pi.model.DefaultPiPipeconf;
26import org.onosproject.net.pi.model.PiPipeconf;
27import org.onosproject.net.pi.model.PiPipelineInterpreter;
28import org.onosproject.net.pi.model.PiPipelineModel;
29import org.onosproject.p4runtime.model.P4InfoParser;
30import org.onosproject.p4runtime.model.P4InfoParserException;
31import org.onosproject.pipelines.fabric.FabricPipeconfService;
32import org.onosproject.pipelines.fabric.impl.behaviour.FabricIntProgrammable;
Daniele Moro464e5ed2019-07-25 14:45:01 -070033import org.onosproject.pipelines.fabric.impl.behaviour.bng.FabricBngProgrammable;
Carmelo Cascone356ab8b2019-09-25 01:02:53 -070034import org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter;
35import org.onosproject.pipelines.fabric.impl.behaviour.pipeliner.FabricPipeliner;
36import org.osgi.service.component.annotations.Activate;
37import org.osgi.service.component.annotations.Component;
38import org.osgi.service.component.annotations.Deactivate;
39import org.slf4j.Logger;
40
41import java.net.URL;
42
43import static com.google.common.base.Preconditions.checkArgument;
44import static com.google.common.base.Preconditions.checkNotNull;
45import static org.slf4j.LoggerFactory.getLogger;
46
47/**
48 * Implementation of the FabricPipeconfService.
49 */
50@Component(immediate = true, service = FabricPipeconfService.class)
51public final class FabricPipeconfManager implements FabricPipeconfService {
52
53 private static final String INT_PROFILE_SUFFIX = "-int";
54 private static final String FULL_PROFILE_SUFFIX = "-full";
Daniele Moro464e5ed2019-07-25 14:45:01 -070055 private static final String BNG_PROFILE_SUFFIX = "-bng";
Daniele Moro7c31a3b2021-06-15 20:53:22 +020056 private static final String UPF_PROFILE_SUFFIX = "-spgw";
Carmelo Cascone356ab8b2019-09-25 01:02:53 -070057
58 private static Logger log = getLogger(FabricPipeconfLoader.class);
59
60 @Activate
61 public void activate() {
62 log.info("Started");
63 }
64
65 @Deactivate
66 public void deactivate() {
67 log.info("Stopped");
68 }
69
70 @Override
71 public PiPipeconf buildFabricPipeconf(
72 DefaultPiPipeconf.Builder builder, String profile, URL p4InfoUrl, URL cpuPortUrl) {
73 return build(builder, profile, p4InfoUrl, cpuPortUrl);
74 }
75
76 static PiPipeconf build(
77 DefaultPiPipeconf.Builder pipeconfBuilder,
78 String profileName, URL p4InfoUrl, URL cpuPortUrl) {
79 checkNotNull(pipeconfBuilder,
80 "pipeconfBuilder cannot be null");
81 checkArgument(profileName != null && !profileName.isEmpty(),
82 "profileName cannot be null or empty");
83 checkNotNull(p4InfoUrl,
84 "p4InfoUrl cannot be null (check if file exists)");
85 checkNotNull(cpuPortUrl,
86 "cpuPortUrl cannot be null (check if file exists)");
87
88 pipeconfBuilder
89 .withPipelineModel(parseP4Info(p4InfoUrl))
90 .addBehaviour(PiPipelineInterpreter.class, FabricInterpreter.class)
91 .addBehaviour(Pipeliner.class, FabricPipeliner.class)
92 .addExtension(PiPipeconf.ExtensionType.P4_INFO_TEXT, p4InfoUrl)
93 .addExtension(PiPipeconf.ExtensionType.CPU_PORT_TXT, cpuPortUrl);
94
95 // Add IntProgrammable behaviour for INT-enabled profiles.
96 if (profileName.endsWith(INT_PROFILE_SUFFIX) ||
97 profileName.endsWith(FULL_PROFILE_SUFFIX)) {
98 pipeconfBuilder.addBehaviour(IntProgrammable.class, FabricIntProgrammable.class);
99 }
Daniele Moro464e5ed2019-07-25 14:45:01 -0700100 // Add BngProgrammable behavior for BNG-enabled pipelines.
101 if (profileName.endsWith(BNG_PROFILE_SUFFIX)) {
102 pipeconfBuilder.addBehaviour(BngProgrammable.class, FabricBngProgrammable.class);
103 }
Daniele Moro7c31a3b2021-06-15 20:53:22 +0200104 // Add UpfProgrammable behavior for UPF-enabled pipelines.
105 if (profileName.contains(UPF_PROFILE_SUFFIX) ||
106 profileName.endsWith(FULL_PROFILE_SUFFIX)) {
107 pipeconfBuilder.addBehaviour(UpfProgrammable.class, FabricUpfProgrammable.class);
108 }
Carmelo Cascone356ab8b2019-09-25 01:02:53 -0700109 return pipeconfBuilder.build();
110 }
111
112 private static PiPipelineModel parseP4Info(URL p4InfoUrl) {
113 try {
114 return P4InfoParser.parse(p4InfoUrl);
115 } catch (P4InfoParserException e) {
116 // FIXME: propagate exception that can be handled by whoever is
117 // trying to build pipeconfs.
118 throw new IllegalStateException(e);
119 }
120 }
121}