88b4b86c149eeb895aa8818346937593ec4896d5
[bgpcep.git] / bgp / flowspec / src / main / java / org / opendaylight / protocol / bgp / flowspec / handlers / FSIpv4FragmentHandler.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.protocol.bgp.flowspec.handlers;
9
10 import org.opendaylight.protocol.util.BitArray;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.Fragment;
12
13 public class FSIpv4FragmentHandler extends AbstractFSFragmentHandler {
14
15     @Override
16     protected final Fragment parseFragment(final byte fragment) {
17         final BitArray bs = BitArray.valueOf(fragment);
18         return new Fragment(bs.get(DONT_FRAGMENT), bs.get(FIRST_FRAGMENT), bs.get(IS_A_FRAGMENT), bs.get(LAST_FRAGMENT));
19     }
20
21     @Override
22     protected final byte serializeFragment(final Fragment fragment) {
23         final BitArray bs = new BitArray(Byte.SIZE);
24         bs.set(DONT_FRAGMENT, fragment.isDoNot());
25         bs.set(FIRST_FRAGMENT, fragment.isFirst());
26         bs.set(IS_A_FRAGMENT, fragment.isIsA());
27         bs.set(LAST_FRAGMENT, fragment.isLast());
28         return bs.toByte();
29     }
30 }