Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPRequestedPathBandwidthObjectParser.java
1 /*
2  * Copyright (c) 2013 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.pcep.impl.object;
9
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.PCEPObject;
12 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
13 import org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nps.concepts.rev130930.Bandwidth;
15
16 /**
17  * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPRequestedPathBandwidthObject
18  * PCEPRequestedPathBandwidthObject}
19  */
20 public class PCEPRequestedPathBandwidthObjectParser implements PCEPObjectParser {
21
22         private static final int BANDWIDTH_F_LENGTH = 4;
23
24         @Override
25         public PCEPObject parse(final byte[] bytes, final boolean processed, final boolean ignored) throws PCEPDeserializerException {
26                 if (bytes == null || bytes.length == 0)
27                         throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
28                 if (bytes.length != BANDWIDTH_F_LENGTH)
29                         throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.length + "; Expected: "
30                                         + BANDWIDTH_F_LENGTH + ".");
31
32                 return new PCEPRequestedPathBandwidthObject(new Bandwidth(bytes), processed, ignored);
33         }
34
35         @Override
36         public byte[] put(final PCEPObject obj) {
37                 if (!(obj instanceof PCEPRequestedPathBandwidthObject))
38                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass()
39                                         + ". Needed PCEPRequestedPathBandwidthObject.");
40
41                 return ((PCEPRequestedPathBandwidthObject) obj).getBandwidth().getValue();
42         }
43 }