2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.services;
11 import org.opendaylight.openflowplugin.api.OFConstants;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
14 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23 import org.opendaylight.yangtools.yang.binding.DataContainer;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
26 final class FlowMessageService<O extends DataObject> extends AbstractMessageService<Flow, FlowMessageBuilder, O> {
27 protected FlowMessageService(final RequestContextStack requestContextStack, final DeviceContext deviceContext, final Class<O> clazz) {
28 super(requestContextStack, deviceContext, clazz);
32 protected OfHeader buildRequest(final Xid xid, final Flow input) throws ServiceException {
33 final FlowMessageBuilder flowMessageBuilder = new FlowMessageBuilder(input);
34 final Class<? extends DataContainer> clazz = input.getImplementedInterface();
36 if (clazz.equals(AddFlowInput.class)
37 || clazz.equals(UpdatedFlow.class)) {
38 flowMessageBuilder.setCommand(FlowModCommand.OFPFCADD);
39 } else if (clazz.equals(RemoveFlowInput.class)
40 || clazz.equals(OriginalFlow.class)) {
41 flowMessageBuilder.setCommand(Boolean.TRUE.equals(input.isStrict())
42 ? FlowModCommand.OFPFCDELETESTRICT
43 : FlowModCommand.OFPFCDELETE);
46 return flowMessageBuilder
47 .setVersion(getVersion())
48 .setXid(xid.getValue())
53 public boolean isSupported() {
54 return super.isSupported() && getVersion() >= OFConstants.OFP_VERSION_1_3;