* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.protocol.pcep.spi;
+package org.opendaylight.protocol.pcep.impl.object;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
+import org.opendaylight.protocol.pcep.spi.ObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-public abstract class AbstractObjectWithSubobjectsParser<BUILDER> implements ObjectParser, ObjectSerializer {
+public abstract class AbstractEROWithSubobjectsParser implements ObjectParser, ObjectSerializer {
- private static final Logger logger = LoggerFactory.getLogger(AbstractObjectWithSubobjectsParser.class);
+ private static final Logger logger = LoggerFactory.getLogger(AbstractEROWithSubobjectsParser.class);
private static final int SUB_TYPE_FLAG_F_LENGTH = 1;
private static final int SUB_LENGTH_F_LENGTH = 1;
protected static final int PADDED_TO = 4;
- private final SubobjectHandlerRegistry subobjReg;
+ private final EROSubobjectHandlerRegistry subobjReg;
- protected AbstractObjectWithSubobjectsParser(final SubobjectHandlerRegistry subobjReg) {
+ protected AbstractEROWithSubobjectsParser(final EROSubobjectHandlerRegistry subobjReg) {
this.subobjReg = Preconditions.checkNotNull(subobjReg);
}
- protected final void parseSubobjects(final BUILDER builder, final byte[] bytes) throws PCEPDeserializerException {
+ protected List<Subobjects> parseSubobjects(final byte[] bytes) throws PCEPDeserializerException {
if (bytes == null) {
throw new IllegalArgumentException("Byte array is mandatory.");
}
boolean loose_flag = false;
int type;
- final Map<CSubobject, Boolean> subs = Maps.newHashMap();
-
byte[] soContentsBytes;
int length;
int offset = 0;
+ final List<Subobjects> subs = Lists.newArrayList();
+
while (offset < bytes.length) {
loose_flag = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
- final CSubobject subObj = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes);
- logger.debug("Subobject was parsed. {}", subObj);
+ final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, loose_flag);
+ logger.debug("Subobject was parsed. {}", sub);
- subs.put(subObj, loose_flag);
+ subs.add(sub);
offset += length;
}
- // addSubobject(builder, subs);
+ return subs;
}
- protected final byte[] serializeSubobject(final Map<CSubobject, Boolean> subobjects) {
+ protected final byte[] serializeSubobject(final List<Subobjects> subobjects) {
final List<byte[]> result = Lists.newArrayList();
int finalLength = 0;
- for (final Entry<CSubobject, Boolean> entry : subobjects.entrySet()) {
-
- final CSubobject subobject = entry.getKey();
+ for (final Subobjects subobject : subobjects) {
- final SubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject);
+ final EROSubobjectSerializer serializer = this.subobjReg.getSubobjectSerializer(subobject);
final byte[] valueBytes = serializer.serializeSubobject(subobject);
final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
- final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (entry.getValue() ? 1 << 7
+ final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isLoose() ? 1 << 7
: 0));
final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
}
return resultBytes;
}
-
- // public abstract void addSubobject(final BUILDER builder, final Map<CSubobject, Boolean> subobjects);
-
}