00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 #include <dtn-config.h>
00019 #endif
00020
00021 #include <oasys/serialize/MarshalSerialize.h>
00022 #include <oasys/util/ScratchBuffer.h>
00023
00024 #include "DTLSR.h"
00025 #include "bundling/Bundle.h"
00026
00027 namespace dtn {
00028
00029
00030 void
00031 DTLSR::LinkParams::serialize(oasys::SerializeAction* a)
00032 {
00033 a->process("state", &state_);
00034 a->process("cost", &cost_);
00035 a->process("delay", &delay_);
00036 a->process("bw", &bw_);
00037 a->process("qcount",&qcount_);
00038 a->process("qsize", &qsize_);
00039 }
00040
00041
00042 void
00043 DTLSR::LinkState::serialize(oasys::SerializeAction* a)
00044 {
00045 a->process("dest", &dest_);
00046 a->process("id", &id_);
00047 a->process("elapsed", &elapsed_);
00048 a->process("params", ¶ms_);
00049 }
00050
00051
00052 void
00053 DTLSR::LSA::serialize(oasys::SerializeAction* a)
00054 {
00055 a->process("seqno", &seqno_);
00056 a->process("links", &links_);
00057 }
00058
00059
00060 void
00061 DTLSR::format_lsa_bundle(Bundle* bundle, const LSA* lsa)
00062 {
00063 oasys::MarshalSize ms(oasys::Serialize::CONTEXT_NETWORK);
00064 if (ms.action(lsa) != 0) {
00065 log_crit_p("/dtn/route/dtlsr", "error sizing lsa");
00066 return;
00067 }
00068 size_t len = ms.size();
00069
00070
00071
00072
00073
00074
00075 oasys::ScratchBuffer<u_char*, 256> buf;
00076
00077 oasys::Marshal m(oasys::Serialize::CONTEXT_NETWORK, &buf);
00078 if (m.action(lsa) != 0) {
00079 log_crit_p("/dtn/route/dtlsr", "error marshalling lsa");
00080 return;
00081 }
00082
00083 bundle->mutable_payload()->set_length(1 + len);
00084
00085 u_char type = MSG_LSA;
00086 bundle->mutable_payload()->write_data(&type, 0, 1);
00087 bundle->mutable_payload()->write_data(buf.buf(), 1, len);
00088 }
00089
00090
00091 bool
00092 DTLSR::parse_lsa_bundle(const Bundle* bundle, LSA* lsa)
00093 {
00094 oasys::ScratchBuffer<u_char*, 256> buf;
00095 size_t len = bundle->payload().length();
00096 bundle->payload().read_data(0, len, buf.buf(len));
00097
00098 if (buf.buf()[0] != MSG_LSA) {
00099 log_warn_p("/dtn/route/dtlsr",
00100 "parse_lsa_bundle: typecode byte %u != MSG_LSA",
00101 buf.buf()[0]);
00102 return false;
00103 }
00104
00105 oasys::Unmarshal um(oasys::Serialize::CONTEXT_NETWORK,
00106 buf.buf() + 1, len - 1);
00107 if (um.action(lsa) != 0) {
00108 log_warn_p("/dtn/route/dtlsr",
00109 "error unmarshalling lsa vector");
00110 return false;
00111 }
00112
00113 return true;
00114 }
00115
00116 }