Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / instruction / AbstractInstructionDeserializer.java
1 /*
2  * Copyright (c) 2013 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.instruction;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.protocol.api.extensibility.HeaderDeserializer;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder;
24
25 /**
26  * @author michal.polkorab
27  *
28  */
29 public abstract class AbstractInstructionDeserializer implements OFDeserializer<Instruction>,
30         HeaderDeserializer<Instruction> {
31
32     @Override
33     public Instruction deserializeHeader(ByteBuf rawMessage) {
34         InstructionBuilder builder = processHeader(rawMessage);
35         rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
36         return builder.build();
37     }
38
39     protected InstructionBuilder processHeader(ByteBuf input) {
40         InstructionBuilder builder = new InstructionBuilder();
41         int type = input.readUnsignedShort();
42         switch (type) {
43         case 1:
44             builder.setType(GotoTable.class);
45             break;
46         case 2:
47             builder.setType(WriteMetadata.class);
48             break;
49         case 3:
50             builder.setType(WriteActions.class);
51             break;
52         case 4:
53             builder.setType(ApplyActions.class);
54             break;
55         case 5:
56             builder.setType(ClearActions.class);
57             break;
58         case 6:
59             builder.setType(Meter.class);
60             break;
61         default:
62             throw new IllegalStateException("Unknown instruction type received, type: " + type);
63         }
64         return builder;
65     }
66 }