BUG-58: refactor to take advantage of netty
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPMessageType.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;
9
10 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
11
12 /**
13  * Type identifier for {@link org.opendaylight.protocol.pcep.PCEPMessage PCEPMessage}
14  */
15 public enum PCEPMessageType {
16         OPEN(1), NOTIFICATION(5), KEEPALIVE(2), RESPONSE(4), REQUEST(3), ERROR(6), CLOSE(7), UPDATE_REQUEST(11), STATUS_REPORT(10),
17         // TODO: replace with actual values by IANA
18         XR_ADD_TUNNEL(8), XR_DELETE_TUNNEL(9), PCCREATE(12);
19
20         private final int identifier;
21
22         PCEPMessageType(final int identifier) {
23                 this.identifier = identifier;
24         }
25
26         public int getIdentifier() {
27                 return this.identifier;
28         }
29
30         public static PCEPMessageType getFromInt(final int type) throws PCEPDeserializerException {
31
32                 for (final PCEPMessageType type_e : PCEPMessageType.values()) {
33                         if (type_e.getIdentifier() == type) {
34                                 return type_e;
35                         }
36                 }
37
38                 throw new PCEPDeserializerException("Unknown PCEPMessage Class identifier. Passed: " + type + "; Known: "
39                                 + PCEPMessageType.values() + ".");
40         }
41 }