Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame^] | 1 | /*
|
| 2 | * Copyright 2015 Open Networking Laboratory
|
| 3 | *
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | * you may not use this file except in compliance with the License.
|
| 6 | * You may obtain a copy of the License at
|
| 7 | *
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | *
|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | * See the License for the specific language governing permissions and
|
| 14 | * limitations under the License.
|
| 15 | */
|
| 16 |
|
| 17 | package org.onosproject.pcepio.protocol;
|
| 18 |
|
| 19 | import org.jboss.netty.buffer.ChannelBuffer;
|
| 20 | import org.onosproject.pcepio.exceptions.PcepParseException;
|
| 21 | import org.slf4j.Logger;
|
| 22 | import org.slf4j.LoggerFactory;
|
| 23 |
|
| 24 | public final class PcepFactories {
|
| 25 |
|
| 26 | protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class);
|
| 27 |
|
| 28 | private static final GenericReader GENERIC_READER = new GenericReader();
|
| 29 |
|
| 30 | public static final byte SHIFT_FLAG = 5;
|
| 31 |
|
| 32 | private PcepFactories() {
|
| 33 | }
|
| 34 |
|
| 35 | /*
|
| 36 | * Returns the instance of PCEP Version.
|
| 37 | *
|
| 38 | * @param version
|
| 39 | * @return PCEP version
|
| 40 | */
|
| 41 | public static PcepFactory getFactory(PcepVersion version) {
|
| 42 | switch (version) {
|
| 43 | case PCEP_1:
|
| 44 | // TODO : to get the pcep version 1 factory
|
| 45 | default:
|
| 46 | throw new IllegalArgumentException("[PcepFactory:]Unknown version: " + version);
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | private static class GenericReader implements PcepMessageReader<PcepMessage> {
|
| 51 |
|
| 52 | @Override
|
| 53 | public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException {
|
| 54 |
|
| 55 | if (!bb.readable()) {
|
| 56 | log.debug("Empty message received");
|
| 57 | throw new PcepParseException("Empty message received");
|
| 58 | }
|
| 59 |
|
| 60 | /*
|
| 61 | * 0 1 2 3
|
| 62 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
| 63 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 64 | * | Ver | Flags | |
|
| 65 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
| 66 | *
|
| 67 | * Currently Version 1 is supported
|
| 68 | * Currently no flags are used, it is all ignored
|
| 69 | */
|
| 70 |
|
| 71 | byte packetVersion = bb.getByte(bb.readerIndex());
|
| 72 | packetVersion = (byte) (packetVersion >> SHIFT_FLAG);
|
| 73 | PcepFactory factory;
|
| 74 |
|
| 75 | switch (packetVersion) {
|
| 76 |
|
| 77 | case 1:
|
| 78 | // TODO : get the factory for version 1
|
| 79 | break;
|
| 80 | default:
|
| 81 | throw new IllegalArgumentException("Unknown Packet version: " + packetVersion);
|
| 82 | }
|
| 83 | // TODO : Read the PCEP message from the factory
|
| 84 | return null;
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 | /*
|
| 89 | * Returns GENERIC_READER.
|
| 90 | *
|
| 91 | * @return GENERIC_READER
|
| 92 | */
|
| 93 | public static PcepMessageReader<PcepMessage> getGenericReader() {
|
| 94 | return GENERIC_READER;
|
| 95 | }
|
| 96 | }
|