Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / singlelayer / SingleLayerFlowService.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.services.singlelayer;
9
10 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
11 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
12 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
13 import org.opendaylight.openflowplugin.impl.services.AbstractSilentErrorService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22 import org.opendaylight.yangtools.yang.binding.DataContainer;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24
25 public final class SingleLayerFlowService<O extends DataObject> extends AbstractSilentErrorService<Flow, O> {
26     public SingleLayerFlowService(final RequestContextStack requestContextStack,
27                                   final DeviceContext deviceContext,
28                                   final Class<O> clazz) {
29         super(requestContextStack, deviceContext, clazz);
30     }
31
32     @Override
33     protected OfHeader buildRequest(final Xid xid, final Flow input) {
34         final FlowMessageBuilder flowMessageBuilder = new FlowMessageBuilder(input);
35         final Class<? extends DataContainer> clazz = input.implementedInterface();
36
37         if (clazz.equals(AddFlowInput.class) || clazz.equals(UpdatedFlow.class)) {
38             flowMessageBuilder.setCommand(FlowModCommand.OFPFCADD);
39         } else if (clazz.equals(RemoveFlowInput.class) || clazz.equals(OriginalFlow.class)) {
40             flowMessageBuilder.setCommand(
41                 Boolean.TRUE.equals(input.getStrict()) ? FlowModCommand.OFPFCDELETESTRICT : FlowModCommand.OFPFCDELETE);
42         }
43
44         return flowMessageBuilder
45                 .setVersion(getVersion())
46                 .setXid(xid.getValue())
47                 .build();
48     }
49 }