blob: f6f181d55f49d321ed4f29aa9d07d40355dfa10d [file] [log] [blame]
Carmelo Cascone00a59962017-06-16 17:51:49 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
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.net.pi.impl;
18
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onosproject.net.Device;
26import org.onosproject.net.device.DeviceService;
27import org.onosproject.net.flow.FlowRule;
28import org.onosproject.net.pi.model.PiPipeconf;
29import org.onosproject.net.pi.runtime.PiFlowRuleTranslationService;
30import org.onosproject.net.pi.runtime.PiTableEntry;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import static org.onosproject.net.pi.impl.PiFlowRuleTranslator.translateFlowRule;
35
36/**
37 * Implementation of the protocol-independent flow rule translation service.
38 */
39@Component(immediate = true)
40@Service
41public class PiFlowRuleTranslationServiceImpl implements PiFlowRuleTranslationService {
42
43 private final Logger log = LoggerFactory.getLogger(this.getClass());
44
45 // TODO: implement cache to speed up translation of flow rules.
46
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected DeviceService deviceService;
49
50 @Activate
51 public void activate() {
52 log.info("Started");
53 }
54
55 @Deactivate
56 public void deactivate() {
57 log.info("Stopped");
58 }
59
60 @Override
61 public PiTableEntry translate(FlowRule rule, PiPipeconf pipeconf)
62 throws PiFlowRuleTranslationException {
63
64 Device device = deviceService.getDevice(rule.deviceId());
65 if (device == null) {
66 throw new PiFlowRuleTranslationException("Unable to get device " + rule.deviceId());
67 }
68
69 return translateFlowRule(rule, pipeconf, device);
70 }
71}
72