Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 00a5996 | 2017-06-16 17:51:49 +0900 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.pi.impl; |
| 18 | |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
| 25 | import org.onosproject.net.Device; |
| 26 | import org.onosproject.net.device.DeviceService; |
| 27 | import org.onosproject.net.flow.FlowRule; |
| 28 | import org.onosproject.net.pi.model.PiPipeconf; |
| 29 | import org.onosproject.net.pi.runtime.PiFlowRuleTranslationService; |
| 30 | import org.onosproject.net.pi.runtime.PiTableEntry; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | import 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 |
| 41 | public 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 | |