8489e5d6a6e7135656aabbbe1095e0cd869cc539
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / TestVendorInformationTlvParser.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.protocol.pcep.impl;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.protocol.pcep.impl.tlv.AbstractVendorInformationTlvParser;
14 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.EnterpriseSpecificInformation;
17 import org.opendaylight.yangtools.yang.binding.DataContainer;
18
19 public class TestVendorInformationTlvParser extends AbstractVendorInformationTlvParser {
20
21     private static final EnterpriseNumber TEST_ENTERPRISE_NUMBER = new EnterpriseNumber(0L);
22
23     @Override
24     public void serializeEnterpriseSpecificInformation(final EnterpriseSpecificInformation enterpriseSpecificInformation,
25             final ByteBuf buffer) {
26         if (enterpriseSpecificInformation instanceof TestEnterpriseSpecificInformation) {
27             buffer.writeInt(((TestEnterpriseSpecificInformation) enterpriseSpecificInformation).getValue());
28         }
29     }
30
31     @Override
32     public EnterpriseSpecificInformation parseEnterpriseSpecificInformation(final ByteBuf buffer)
33             throws PCEPDeserializerException {
34         return new TestEnterpriseSpecificInformation(buffer.readInt());
35     }
36
37     @Override
38     public EnterpriseNumber getEnterpriseNumber() {
39         return TEST_ENTERPRISE_NUMBER;
40     }
41
42     protected static final class TestEnterpriseSpecificInformation implements EnterpriseSpecificInformation {
43
44         private final int value;
45
46         public TestEnterpriseSpecificInformation(final int value) {
47             this.value = value;
48         }
49
50         public int getValue() {
51             return value;
52         }
53
54         @Override
55         public Class<? extends DataContainer> getImplementedInterface() {
56             return TestEnterpriseSpecificInformation.class;
57         }
58
59         @Override
60         public int hashCode() {
61             final int prime = 31;
62             int result = 1;
63             result = prime * result + value;
64             return result;
65         }
66
67         @Override
68         public boolean equals(final Object obj) {
69             if (this == obj) {
70                 return true;
71             }
72             if (obj == null) {
73                 return false;
74             }
75             if (getClass() != obj.getClass()) {
76                 return false;
77             }
78             TestEnterpriseSpecificInformation other = (TestEnterpriseSpecificInformation) obj;
79             if (value != other.value) {
80                 return false;
81             }
82             return true;
83         }
84     }
85
86 }