BUG-4085: Li: provisioning translators
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / translator / FlowRemovedTranslator.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.impl.translator;
9
10 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
11 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
12 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
13 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
19
20 /**
21  * translate {@link FlowRemoved} message to FlowRemoved notification (omit instructions)
22  */
23 public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> {
24
25     @Override
26     public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved translate(FlowRemoved input, DeviceContext deviceContext, Object connectionDistinguisher) {
27         FlowRemovedBuilder flowRemovedBld = new FlowRemovedBuilder()
28                 .setMatch(translateMatch(input, deviceContext).build())
29                 .setCookie(new FlowCookie(input.getCookie()))
30                 .setNode(new NodeRef(deviceContext.getDeviceState().getNodeInstanceIdentifier()))
31                 .setPriority(input.getPriority())
32                 .setTableId(input.getTableId().getValue().shortValue());
33
34         return flowRemovedBld.build();
35     }
36
37     protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceContext deviceContext) {
38         return MatchConvertorImpl.fromOFMatchToSALMatch(flowRemoved.getMatch(),
39                 deviceContext.getDeviceState().getFeatures().getDatapathId(), OpenflowVersion.OF13);
40     }
41 }