package org.kne.cloud.network.srv6;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.net.Inet6Address;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.kne.cloud.network.NetworkPacket;
import org.kne.cloud.network.ipv6.IPv6AddressGroup;

public class RouterInfoPacket extends KLALBRoutingProtocolPacket implements Serializable{

	public RouterInfoPacket(RouterInfo routerInfo, boolean flood,long asn) {
		super(RINFO);
		getHeader().put(1,(byte) (flood?1:0));
		getHeader().putLong(2,asn);
		this.rinfo=routerInfo;
	}
	protected RouterInfoPacket(ByteBuffer bb) {
		super(bb);
	}
	
	private RouterInfo rinfo;
	
	public boolean isFlood() {
		return (getHeader().get(1)&1)==1;
	}
	
	public long getASN() {
		return getHeader().getLong(2);
	}
	
	public RouterInfo getRinfo() {
		return rinfo;
	}
	@Override
	protected long getHeaderSize() {
		return super.getHeaderSize()+9;
	}
	@Override
	public long getTotalLength() {
		return super.getTotalLength();
	}
	public void setRinfo(RouterInfo rinfo) {
		this.rinfo = rinfo;
	}
	@Override
	public String toString() {
		return rinfo.toString();
	}
	

	@Override
	public void writeToChannel(WritableByteChannel dto) throws IOException {
		super.writeToChannel(dto);
		rinfo.writeToChannel(dto);
	}
	@Override
	public void readFromChannel(ReadableByteChannel din, long length) throws IOException {
		super.readFromChannel(din, length);
		rinfo=new RouterInfo();
		rinfo.readFromChannel(din, length);
	}

}
