diff --git a/ns-3-allinone/netanim/Makefile b/ns-3-allinone/netanim/Makefile new file mode 100644 index 0000000..de22f93 --- /dev/null +++ b/ns-3-allinone/netanim/Makefile @@ -0,0 +1,1107 @@ +############################################################################# +# Makefile for building: libNetAnimOnline.so.1.0.0 +# Generated by qmake (2.01a) (Qt 4.8.7) on: ?? ??? 12 19:40:34 2017 +# Project: NetAnimOnline.pro +# Template: lib +# Command: /usr/lib/x86_64-linux-gnu/qt4/bin/qmake -o Makefile NetAnimOnline.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DNS3_LOG_ENABLE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES) +CXXFLAGS = -m64 -pipe -std=c++11 -O2 -Wall -W -D_REENTRANT -fPIC $(DEFINES) +INCPATH = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -Iqtpropertybrowser/src -I/usr/local/include/ns3-dev -I. +LINK = g++ +LFLAGS = -m64 -Wl,-rpath='$$ORIGIN' -Wl,-rpath-link='$$ORIGIN' -Wl,-z,origin -lc -Wl,-O1 -shared -Wl,-soname,libNetAnimOnline.so.1 +LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/lib/x86_64-linux-gnu/qt4/bin/qmake +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = strip +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = main.cpp \ + log.cpp \ + fatal-error.cpp \ + fatal-impl.cpp \ + logqt.cpp \ + resizeableitem.cpp \ + animnode.cpp \ + animatorscene.cpp \ + animpacket.cpp \ + netanim.cpp \ + animatormode.cpp \ + mode.cpp \ + animxmlparser.cpp \ + animatorview.cpp \ + animlink.cpp \ + animresource.cpp \ + statsview.cpp \ + statsmode.cpp \ + routingxmlparser.cpp \ + routingstatsscene.cpp \ + interfacestatsscene.cpp \ + flowmonxmlparser.cpp \ + flowmonstatsscene.cpp \ + textbubble.cpp \ + qtpropertybrowser/src/qtvariantproperty.cpp \ + qtpropertybrowser/src/qttreepropertybrowser.cpp \ + qtpropertybrowser/src/qtpropertymanager.cpp \ + qtpropertybrowser/src/qtpropertybrowserutils.cpp \ + qtpropertybrowser/src/qtpropertybrowser.cpp \ + qtpropertybrowser/src/qtgroupboxpropertybrowser.cpp \ + qtpropertybrowser/src/qteditorfactory.cpp \ + qtpropertybrowser/src/qtbuttonpropertybrowser.cpp \ + animpropertybrowser.cpp \ + qtpropertybrowser/src/filepathmanager.cpp \ + qtpropertybrowser/src/fileeditfactory.cpp \ + qtpropertybrowser/src/fileedit.cpp \ + packetsmode.cpp \ + packetsview.cpp \ + packetsscene.cpp \ + graphpacket.cpp \ + table.cpp \ + countertablesscene.cpp \ + qcustomplot.cpp moc_animatorscene.cpp \ + moc_animpacket.cpp \ + moc_netanim.cpp \ + moc_animatormode.cpp \ + moc_statsmode.cpp \ + moc_qtpropertybrowserutils_p.cpp \ + moc_animpropertybrowser.cpp \ + moc_filepathmanager.cpp \ + moc_fileeditfactory.cpp \ + moc_fileedit.cpp \ + moc_packetsmode.cpp \ + moc_table.cpp \ + moc_qcustomplot.cpp \ + qrc_resources.cpp \ + qrc_qtpropertybrowser.cpp +OBJECTS = main.o \ + log.o \ + fatal-error.o \ + fatal-impl.o \ + logqt.o \ + resizeableitem.o \ + animnode.o \ + animatorscene.o \ + animpacket.o \ + netanim.o \ + animatormode.o \ + mode.o \ + animxmlparser.o \ + animatorview.o \ + animlink.o \ + animresource.o \ + statsview.o \ + statsmode.o \ + routingxmlparser.o \ + routingstatsscene.o \ + interfacestatsscene.o \ + flowmonxmlparser.o \ + flowmonstatsscene.o \ + textbubble.o \ + qtvariantproperty.o \ + qttreepropertybrowser.o \ + qtpropertymanager.o \ + qtpropertybrowserutils.o \ + qtpropertybrowser.o \ + qtgroupboxpropertybrowser.o \ + qteditorfactory.o \ + qtbuttonpropertybrowser.o \ + animpropertybrowser.o \ + filepathmanager.o \ + fileeditfactory.o \ + fileedit.o \ + packetsmode.o \ + packetsview.o \ + packetsscene.o \ + graphpacket.o \ + table.o \ + countertablesscene.o \ + qcustomplot.o \ + moc_animatorscene.o \ + moc_animpacket.o \ + moc_netanim.o \ + moc_animatormode.o \ + moc_statsmode.o \ + moc_qtpropertybrowserutils_p.o \ + moc_animpropertybrowser.o \ + moc_filepathmanager.o \ + moc_fileeditfactory.o \ + moc_fileedit.o \ + moc_packetsmode.o \ + moc_table.o \ + moc_qcustomplot.o \ + qrc_resources.o \ + qrc_qtpropertybrowser.o +DIST = /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/common/gcc-base.conf \ + /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/share/qt4/mkspecs/common/g++-base.conf \ + /usr/share/qt4/mkspecs/common/g++-unix.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/shared.prf \ + /usr/share/qt4/mkspecs/features/dll.prf \ + /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + NetAnimOnline.pro +QMAKE_TARGET = NetAnimOnline +DESTDIR = +TARGET = libNetAnimOnline.so.1.0.0 +TARGETA = libNetAnimOnline.a +TARGETD = libNetAnimOnline.so.1.0.0 +TARGET0 = libNetAnimOnline.so +TARGET1 = libNetAnimOnline.so.1 +TARGET2 = libNetAnimOnline.so.1.0 + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): $(OBJECTS) $(SUBLIBS) $(OBJCOMP) + -$(DEL_FILE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS) $(OBJCOMP) + -ln -s $(TARGET) $(TARGET0) + -ln -s $(TARGET) $(TARGET1) + -ln -s $(TARGET) $(TARGET2) + + + +staticlib: $(TARGETA) + +$(TARGETA): $(OBJECTS) $(OBJCOMP) + -$(DEL_FILE) $(TARGETA) + $(AR) $(TARGETA) $(OBJECTS) + +Makefile: NetAnimOnline.pro /usr/share/qt4/mkspecs/linux-g++-64/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/common/gcc-base.conf \ + /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/share/qt4/mkspecs/common/g++-base.conf \ + /usr/share/qt4/mkspecs/common/g++-unix.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/shared.prf \ + /usr/share/qt4/mkspecs/features/dll.prf \ + /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + /usr/lib/x86_64-linux-gnu/libQtGui.prl \ + /usr/lib/x86_64-linux-gnu/libQtCore.prl + $(QMAKE) -o Makefile NetAnimOnline.pro +/usr/share/qt4/mkspecs/common/unix.conf: +/usr/share/qt4/mkspecs/common/linux.conf: +/usr/share/qt4/mkspecs/common/gcc-base.conf: +/usr/share/qt4/mkspecs/common/gcc-base-unix.conf: +/usr/share/qt4/mkspecs/common/g++-base.conf: +/usr/share/qt4/mkspecs/common/g++-unix.conf: +/usr/share/qt4/mkspecs/qconfig.pri: +/usr/share/qt4/mkspecs/features/qt_functions.prf: +/usr/share/qt4/mkspecs/features/qt_config.prf: +/usr/share/qt4/mkspecs/features/exclusive_builds.prf: +/usr/share/qt4/mkspecs/features/default_pre.prf: +/usr/share/qt4/mkspecs/features/release.prf: +/usr/share/qt4/mkspecs/features/default_post.prf: +/usr/share/qt4/mkspecs/features/shared.prf: +/usr/share/qt4/mkspecs/features/dll.prf: +/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: +/usr/share/qt4/mkspecs/features/warn_on.prf: +/usr/share/qt4/mkspecs/features/qt.prf: +/usr/share/qt4/mkspecs/features/unix/thread.prf: +/usr/share/qt4/mkspecs/features/moc.prf: +/usr/share/qt4/mkspecs/features/resources.prf: +/usr/share/qt4/mkspecs/features/uic.prf: +/usr/share/qt4/mkspecs/features/yacc.prf: +/usr/share/qt4/mkspecs/features/lex.prf: +/usr/share/qt4/mkspecs/features/include_source_dir.prf: +/usr/lib/x86_64-linux-gnu/libQtGui.prl: +/usr/lib/x86_64-linux-gnu/libQtCore.prl: +qmake: FORCE + @$(QMAKE) -o Makefile NetAnimOnline.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/NetAnimOnline1.0.0 || $(MKDIR) .tmp/NetAnimOnline1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/NetAnimOnline1.0.0/ && $(COPY_FILE) --parents log.h fatal-error.h fatal-impl.h abort.h assert.h logqt.h animatorconstants.h resizeableitem.h animnode.h common.h animatorscene.h timevalue.h animpacket.h netanim.h animatormode.h animatorview.h mode.h animxmlparser.h animevent.h animlink.h animresource.h statsview.h statsmode.h statisticsconstants.h routingxmlparser.h routingstatsscene.h interfacestatsscene.h flowmonxmlparser.h flowmonstatsscene.h textbubble.h qtpropertybrowser/src/QtVariantPropertyManager qtpropertybrowser/src/QtVariantProperty qtpropertybrowser/src/qtvariantproperty.h qtpropertybrowser/src/QtVariantEditorFactory qtpropertybrowser/src/QtTreePropertyBrowser qtpropertybrowser/src/qttreepropertybrowser.h qtpropertybrowser/src/QtTimePropertyManager qtpropertybrowser/src/QtTimeEditFactory qtpropertybrowser/src/QtStringPropertyManager qtpropertybrowser/src/QtSpinBoxFactory qtpropertybrowser/src/QtSliderFactory qtpropertybrowser/src/QtSizePropertyManager qtpropertybrowser/src/QtSizePolicyPropertyManager qtpropertybrowser/src/QtSizeFPropertyManager qtpropertybrowser/src/QtScrollBarFactory qtpropertybrowser/src/QtRectPropertyManager qtpropertybrowser/src/QtRectFPropertyManager qtpropertybrowser/src/qtpropertymanager.h qtpropertybrowser/src/qtpropertybrowserutils_p.h qtpropertybrowser/src/qtpropertybrowser.h qtpropertybrowser/src/QtProperty qtpropertybrowser/src/QtPointPropertyManager qtpropertybrowser/src/QtPointFPropertyManager qtpropertybrowser/src/QtLocalePropertyManager qtpropertybrowser/src/QtLineEditFactory qtpropertybrowser/src/QtKeySequencePropertyManager qtpropertybrowser/src/QtKeySequenceEditorFactory qtpropertybrowser/src/QtIntPropertyManager qtpropertybrowser/src/QtGroupPropertyManager qtpropertybrowser/src/QtGroupBoxPropertyBrowser qtpropertybrowser/src/qtgroupboxpropertybrowser.h qtpropertybrowser/src/QtFontPropertyManager qtpropertybrowser/src/QtFontEditorFactory qtpropertybrowser/src/QtFlagPropertyManager qtpropertybrowser/src/QtEnumPropertyManager qtpropertybrowser/src/QtEnumEditorFactory qtpropertybrowser/src/qteditorfactory.h qtpropertybrowser/src/QtDoubleSpinBoxFactory qtpropertybrowser/src/QtDoublePropertyManager qtpropertybrowser/src/QtDateTimePropertyManager qtpropertybrowser/src/QtDateTimeEditFactory qtpropertybrowser/src/QtDatePropertyManager qtpropertybrowser/src/QtDateEditFactory qtpropertybrowser/src/QtCursorPropertyManager qtpropertybrowser/src/QtCursorEditorFactory qtpropertybrowser/src/QtColorPropertyManager qtpropertybrowser/src/QtColorEditorFactory qtpropertybrowser/src/QtCheckBoxFactory qtpropertybrowser/src/QtCharPropertyManager qtpropertybrowser/src/QtCharEditorFactory qtpropertybrowser/src/QtButtonPropertyBrowser qtpropertybrowser/src/qtbuttonpropertybrowser.h qtpropertybrowser/src/QtBrowserItem qtpropertybrowser/src/QtBoolPropertyManager qtpropertybrowser/src/QtAbstractPropertyManager qtpropertybrowser/src/QtAbstractPropertyBrowser qtpropertybrowser/src/QtAbstractEditorFactoryBase animpropertybrowser.h qtpropertybrowser/src/filepathmanager.h qtpropertybrowser/src/fileeditfactory.h qtpropertybrowser/src/fileedit.h packetsmode.h packetsview.h packetsscene.h graphpacket.h table.h countertablesscene.h qcustomplot.h .tmp/NetAnimOnline1.0.0/ && $(COPY_FILE) --parents resources.qrc qtpropertybrowser/src/qtpropertybrowser.qrc .tmp/NetAnimOnline1.0.0/ && $(COPY_FILE) --parents main.cpp log.cpp fatal-error.cpp fatal-impl.cpp logqt.cpp resizeableitem.cpp animnode.cpp animatorscene.cpp animpacket.cpp netanim.cpp animatormode.cpp mode.cpp animxmlparser.cpp animatorview.cpp animlink.cpp animresource.cpp statsview.cpp statsmode.cpp routingxmlparser.cpp routingstatsscene.cpp interfacestatsscene.cpp flowmonxmlparser.cpp flowmonstatsscene.cpp textbubble.cpp qtpropertybrowser/src/qtvariantproperty.cpp qtpropertybrowser/src/qttreepropertybrowser.cpp qtpropertybrowser/src/qtpropertymanager.cpp qtpropertybrowser/src/qtpropertybrowserutils.cpp qtpropertybrowser/src/qtpropertybrowser.cpp qtpropertybrowser/src/qtgroupboxpropertybrowser.cpp qtpropertybrowser/src/qteditorfactory.cpp qtpropertybrowser/src/qtbuttonpropertybrowser.cpp animpropertybrowser.cpp qtpropertybrowser/src/filepathmanager.cpp qtpropertybrowser/src/fileeditfactory.cpp qtpropertybrowser/src/fileedit.cpp packetsmode.cpp packetsview.cpp packetsscene.cpp graphpacket.cpp table.cpp countertablesscene.cpp qcustomplot.cpp .tmp/NetAnimOnline1.0.0/ && (cd `dirname .tmp/NetAnimOnline1.0.0` && $(TAR) NetAnimOnline1.0.0.tar NetAnimOnline1.0.0 && $(COMPRESS) NetAnimOnline1.0.0.tar) && $(MOVE) `dirname .tmp/NetAnimOnline1.0.0`/NetAnimOnline1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/NetAnimOnline1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) $(TARGET0) $(TARGET1) $(TARGET2) $(TARGETA) + -$(DEL_FILE) Makefile + + +check: first + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: moc_animatorscene.cpp moc_animpacket.cpp moc_netanim.cpp moc_animatormode.cpp moc_statsmode.cpp moc_qtvariantproperty.cpp moc_qttreepropertybrowser.cpp moc_qtpropertymanager.cpp moc_qtpropertybrowserutils_p.cpp moc_qtpropertybrowser.cpp moc_qtgroupboxpropertybrowser.cpp moc_qteditorfactory.cpp moc_qtbuttonpropertybrowser.cpp moc_animpropertybrowser.cpp moc_filepathmanager.cpp moc_fileeditfactory.cpp moc_fileedit.cpp moc_packetsmode.cpp moc_table.cpp moc_qcustomplot.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_animatorscene.cpp moc_animpacket.cpp moc_netanim.cpp moc_animatormode.cpp moc_statsmode.cpp moc_qtvariantproperty.cpp moc_qttreepropertybrowser.cpp moc_qtpropertymanager.cpp moc_qtpropertybrowserutils_p.cpp moc_qtpropertybrowser.cpp moc_qtgroupboxpropertybrowser.cpp moc_qteditorfactory.cpp moc_qtbuttonpropertybrowser.cpp moc_animpropertybrowser.cpp moc_filepathmanager.cpp moc_fileeditfactory.cpp moc_fileedit.cpp moc_packetsmode.cpp moc_table.cpp moc_qcustomplot.cpp +moc_animatorscene.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animnode.h \ + resizeableitem.h \ + animatorconstants.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorscene.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) animatorscene.h -o moc_animatorscene.cpp + +moc_animpacket.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animatorconstants.h \ + timevalue.h \ + animevent.h \ + animpacket.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) animpacket.h -o moc_animpacket.cpp + +moc_netanim.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h \ + netanim.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) netanim.h -o moc_netanim.cpp + +moc_animatormode.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + animatormode.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) animatormode.h -o moc_animatormode.cpp + +moc_statsmode.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h \ + statsmode.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) statsmode.h -o moc_statsmode.cpp + +moc_qtvariantproperty.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtvariantproperty.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtvariantproperty.h -o moc_qtvariantproperty.cpp + +moc_qttreepropertybrowser.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qttreepropertybrowser.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qttreepropertybrowser.h -o moc_qttreepropertybrowser.cpp + +moc_qtpropertymanager.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtpropertymanager.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtpropertymanager.h -o moc_qtpropertymanager.cpp + +moc_qtpropertybrowserutils_p.cpp: qtpropertybrowser/src/qtpropertybrowserutils_p.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtpropertybrowserutils_p.h -o moc_qtpropertybrowserutils_p.cpp + +moc_qtpropertybrowser.cpp: qtpropertybrowser/src/qtpropertybrowser.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtpropertybrowser.h -o moc_qtpropertybrowser.cpp + +moc_qtgroupboxpropertybrowser.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtgroupboxpropertybrowser.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtgroupboxpropertybrowser.h -o moc_qtgroupboxpropertybrowser.cpp + +moc_qteditorfactory.cpp: qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qteditorfactory.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qteditorfactory.h -o moc_qteditorfactory.cpp + +moc_qtbuttonpropertybrowser.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtbuttonpropertybrowser.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtbuttonpropertybrowser.h -o moc_qtbuttonpropertybrowser.cpp + +moc_animpropertybrowser.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + table.h \ + animpropertybrowser.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) animpropertybrowser.h -o moc_animpropertybrowser.cpp + +moc_filepathmanager.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/filepathmanager.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/filepathmanager.h -o moc_filepathmanager.cpp + +moc_fileeditfactory.cpp: qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/filepathmanager.h \ + qtpropertybrowser/src/fileeditfactory.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/fileeditfactory.h -o moc_fileeditfactory.cpp + +moc_fileedit.cpp: qtpropertybrowser/src/fileedit.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/fileedit.h -o moc_fileedit.cpp + +moc_packetsmode.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h \ + table.h \ + packetsmode.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) packetsmode.h -o moc_packetsmode.cpp + +moc_table.cpp: common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + table.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) table.h -o moc_table.cpp + +moc_qcustomplot.cpp: qcustomplot.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qcustomplot.h -o moc_qcustomplot.cpp + +compiler_rcc_make_all: qrc_resources.cpp qrc_qtpropertybrowser.cpp +compiler_rcc_clean: + -$(DEL_FILE) qrc_resources.cpp qrc_qtpropertybrowser.cpp +qrc_resources.cpp: resources.qrc \ + animator_wirelesscircles.svg \ + animator_zoomout.svg \ + animator_nodesysid.svg \ + animator_showpackets.svg \ + battery_icon_4.png \ + animator_reload.svg \ + battery_icon_0.png \ + animator_zoomin.svg \ + animator_pause.svg \ + battery_icon_3.png \ + animator_play.svg \ + animator_fileopen.svg \ + animator_packetstats.svg \ + animator_step.svg \ + battery_icon_2.png \ + netanim-logo.png \ + animator_grid.svg \ + animator_mouseposition.png \ + animator_nodeid.svg \ + battery_icon_1.png + /usr/lib/x86_64-linux-gnu/qt4/bin/rcc -name resources resources.qrc -o qrc_resources.cpp + +qrc_qtpropertybrowser.cpp: qtpropertybrowser/src/qtpropertybrowser.qrc \ + qtpropertybrowser/src/images/cursor-vsplit.png \ + qtpropertybrowser/src/images/cursor-sizeh.png \ + qtpropertybrowser/src/images/cursor-forbidden.png \ + qtpropertybrowser/src/images/cursor-sizev.png \ + qtpropertybrowser/src/images/cursor-whatsthis.png \ + qtpropertybrowser/src/images/cursor-busy.png \ + qtpropertybrowser/src/images/cursor-wait.png \ + qtpropertybrowser/src/images/cursor-ibeam.png \ + qtpropertybrowser/src/images/cursor-hand.png \ + qtpropertybrowser/src/images/cursor-openhand.png \ + qtpropertybrowser/src/images/cursor-sizeall.png \ + qtpropertybrowser/src/images/cursor-sizef.png \ + qtpropertybrowser/src/images/cursor-sizeb.png \ + qtpropertybrowser/src/images/cursor-hsplit.png \ + qtpropertybrowser/src/images/cursor-cross.png \ + qtpropertybrowser/src/images/cursor-closedhand.png \ + qtpropertybrowser/src/images/cursor-arrow.png \ + qtpropertybrowser/src/images/cursor-uparrow.png + /usr/lib/x86_64-linux-gnu/qt4/bin/rcc -name qtpropertybrowser qtpropertybrowser/src/qtpropertybrowser.qrc -o qrc_qtpropertybrowser.cpp + +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: qttreepropertybrowser.moc qtpropertymanager.moc qteditorfactory.moc +compiler_moc_source_clean: + -$(DEL_FILE) qttreepropertybrowser.moc qtpropertymanager.moc qteditorfactory.moc +qttreepropertybrowser.moc: qtpropertybrowser/src/qttreepropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + moc_qttreepropertybrowser.cpp \ + qtpropertybrowser/src/qttreepropertybrowser.cpp + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qttreepropertybrowser.cpp -o qttreepropertybrowser.moc + +qtpropertymanager.moc: qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowserutils_p.h \ + moc_qtpropertymanager.cpp \ + qtpropertybrowser/src/qtpropertymanager.cpp + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qtpropertymanager.cpp -o qtpropertymanager.moc + +qteditorfactory.moc: qtpropertybrowser/src/qteditorfactory.h \ + qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowserutils_p.h \ + moc_qteditorfactory.cpp \ + qtpropertybrowser/src/qteditorfactory.cpp + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) qtpropertybrowser/src/qteditorfactory.cpp -o qteditorfactory.moc + +compiler_uic_make_all: +compiler_uic_clean: +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_moc_source_clean + +####### Compile + +main.o: main.cpp netanim.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp + +log.o: log.cpp log.h \ + assert.h \ + fatal-error.h \ + fatal-impl.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o log.o log.cpp + +fatal-error.o: fatal-error.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o fatal-error.o fatal-error.cpp + +fatal-impl.o: fatal-impl.cpp fatal-impl.h \ + log.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o fatal-impl.o fatal-impl.cpp + +logqt.o: logqt.cpp logqt.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animpacket.h \ + animatorconstants.h \ + timevalue.h \ + animevent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o logqt.o logqt.cpp + +resizeableitem.o: resizeableitem.cpp resizeableitem.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animatorconstants.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o resizeableitem.o resizeableitem.cpp + +animnode.o: animnode.cpp animnode.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + resizeableitem.h \ + animatorconstants.h \ + animresource.h \ + animatorview.h \ + animatorscene.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animnode.o animnode.cpp + +animatorscene.o: animatorscene.cpp animatorscene.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animnode.h \ + resizeableitem.h \ + animatorconstants.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + animatormode.h \ + mode.h \ + animxmlparser.h \ + animpropertybrowser.h \ + table.h \ + logqt.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animatorscene.o animatorscene.cpp + +animpacket.o: animpacket.cpp animpacket.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animatorconstants.h \ + timevalue.h \ + animevent.h \ + animnode.h \ + resizeableitem.h \ + animatorview.h \ + animatorscene.h \ + animlink.h \ + logqt.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animpacket.o animpacket.cpp + +netanim.o: netanim.cpp netanim.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + animxmlparser.h \ + statsmode.h \ + packetsmode.h \ + table.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o netanim.o netanim.cpp + +animatormode.o: animatormode.cpp common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + animresource.h \ + statsmode.h \ + animpropertybrowser.h \ + table.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animatormode.o animatormode.cpp + +mode.o: mode.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mode.o mode.cpp + +animxmlparser.o: animxmlparser.cpp common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animxmlparser.h \ + animevent.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animatorview.h \ + mode.h \ + animresource.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animxmlparser.o animxmlparser.cpp + +animatorview.o: animatorview.cpp animatorview.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animatorconstants.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animatorview.o animatorview.cpp + +animlink.o: animlink.cpp animnode.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + resizeableitem.h \ + animatorconstants.h \ + animlink.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animlink.o animlink.cpp + +animresource.o: animresource.cpp animresource.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animresource.o animresource.cpp + +statsview.o: statsview.cpp statsview.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o statsview.o statsview.cpp + +statsmode.o: statsmode.cpp animatorscene.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + animnode.h \ + resizeableitem.h \ + animatorconstants.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatormode.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + routingxmlparser.h \ + statisticsconstants.h \ + statsmode.h \ + statsview.h \ + interfacestatsscene.h \ + routingstatsscene.h \ + flowmonstatsscene.h \ + flowmonxmlparser.h \ + countertablesscene.h \ + table.h \ + qcustomplot.h \ + textbubble.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o statsmode.o statsmode.cpp + +routingxmlparser.o: routingxmlparser.cpp routingxmlparser.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + statsmode.h \ + mode.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + animxmlparser.h \ + routingstatsscene.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o routingxmlparser.o routingxmlparser.cpp + +routingstatsscene.o: routingstatsscene.cpp routingstatsscene.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + timevalue.h \ + routingxmlparser.h \ + textbubble.h \ + statisticsconstants.h \ + statsmode.h \ + mode.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + animxmlparser.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o routingstatsscene.o routingstatsscene.cpp + +interfacestatsscene.o: interfacestatsscene.cpp interfacestatsscene.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + textbubble.h \ + statisticsconstants.h \ + statsmode.h \ + mode.h \ + animlink.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + animxmlparser.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o interfacestatsscene.o interfacestatsscene.cpp + +flowmonxmlparser.o: flowmonxmlparser.cpp common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + flowmonxmlparser.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + flowmonstatsscene.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o flowmonxmlparser.o flowmonxmlparser.cpp + +flowmonstatsscene.o: flowmonstatsscene.cpp statsmode.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h \ + flowmonstatsscene.h \ + timevalue.h \ + flowmonxmlparser.h \ + statisticsconstants.h \ + textbubble.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o flowmonstatsscene.o flowmonstatsscene.cpp + +textbubble.o: textbubble.cpp textbubble.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o textbubble.o textbubble.cpp + +qtvariantproperty.o: qtpropertybrowser/src/qtvariantproperty.cpp qtpropertybrowser/src/qtvariantproperty.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qteditorfactory.h \ + moc_qtvariantproperty.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtvariantproperty.o qtpropertybrowser/src/qtvariantproperty.cpp + +qttreepropertybrowser.o: qtpropertybrowser/src/qttreepropertybrowser.cpp qtpropertybrowser/src/qttreepropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + moc_qttreepropertybrowser.cpp \ + qttreepropertybrowser.moc + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qttreepropertybrowser.o qtpropertybrowser/src/qttreepropertybrowser.cpp + +qtpropertymanager.o: qtpropertybrowser/src/qtpropertymanager.cpp qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowserutils_p.h \ + moc_qtpropertymanager.cpp \ + qtpropertymanager.moc + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtpropertymanager.o qtpropertybrowser/src/qtpropertymanager.cpp + +qtpropertybrowserutils.o: qtpropertybrowser/src/qtpropertybrowserutils.cpp qtpropertybrowser/src/qtpropertybrowserutils_p.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtpropertybrowserutils.o qtpropertybrowser/src/qtpropertybrowserutils.cpp + +qtpropertybrowser.o: qtpropertybrowser/src/qtpropertybrowser.cpp qtpropertybrowser/src/qtpropertybrowser.h \ + moc_qtpropertybrowser.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtpropertybrowser.o qtpropertybrowser/src/qtpropertybrowser.cpp + +qtgroupboxpropertybrowser.o: qtpropertybrowser/src/qtgroupboxpropertybrowser.cpp qtpropertybrowser/src/qtgroupboxpropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + moc_qtgroupboxpropertybrowser.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtgroupboxpropertybrowser.o qtpropertybrowser/src/qtgroupboxpropertybrowser.cpp + +qteditorfactory.o: qtpropertybrowser/src/qteditorfactory.cpp qtpropertybrowser/src/qteditorfactory.h \ + qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowserutils_p.h \ + moc_qteditorfactory.cpp \ + qteditorfactory.moc + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qteditorfactory.o qtpropertybrowser/src/qteditorfactory.cpp + +qtbuttonpropertybrowser.o: qtpropertybrowser/src/qtbuttonpropertybrowser.cpp qtpropertybrowser/src/qtbuttonpropertybrowser.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + moc_qtbuttonpropertybrowser.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qtbuttonpropertybrowser.o qtpropertybrowser/src/qtbuttonpropertybrowser.cpp + +animpropertybrowser.o: animpropertybrowser.cpp animpropertybrowser.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + table.h \ + animnode.h \ + resizeableitem.h \ + animatorconstants.h \ + animatormode.h \ + animatorscene.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + animresource.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o animpropertybrowser.o animpropertybrowser.cpp + +filepathmanager.o: qtpropertybrowser/src/filepathmanager.cpp qtpropertybrowser/src/filepathmanager.h \ + qtpropertybrowser/src/qtpropertybrowser.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o filepathmanager.o qtpropertybrowser/src/filepathmanager.cpp + +fileeditfactory.o: qtpropertybrowser/src/fileeditfactory.cpp qtpropertybrowser/src/fileeditfactory.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/filepathmanager.h \ + qtpropertybrowser/src/fileedit.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o fileeditfactory.o qtpropertybrowser/src/fileeditfactory.cpp + +fileedit.o: qtpropertybrowser/src/fileedit.cpp qtpropertybrowser/src/fileedit.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o fileedit.o qtpropertybrowser/src/fileedit.cpp + +packetsmode.o: packetsmode.cpp packetsmode.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + mode.h \ + table.h \ + packetsview.h \ + packetsscene.h \ + textbubble.h \ + animatormode.h \ + animatorconstants.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + animxmlparser.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o packetsmode.o packetsmode.cpp + +packetsview.o: packetsview.cpp packetsview.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + packetsscene.h \ + textbubble.h \ + table.h \ + logqt.h \ + animpacket.h \ + animatorconstants.h \ + timevalue.h \ + animevent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o packetsview.o packetsview.cpp + +packetsscene.o: packetsscene.cpp packetsscene.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + textbubble.h \ + table.h \ + logqt.h \ + animpacket.h \ + animatorconstants.h \ + timevalue.h \ + animevent.h \ + graphpacket.h \ + animatormode.h \ + animatorscene.h \ + animnode.h \ + resizeableitem.h \ + animlink.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + packetsmode.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o packetsscene.o packetsscene.cpp + +graphpacket.o: graphpacket.cpp graphpacket.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + packetsview.h \ + logqt.h \ + animpacket.h \ + animatorconstants.h \ + timevalue.h \ + animevent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o graphpacket.o graphpacket.cpp + +table.o: table.cpp table.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o table.o table.cpp + +countertablesscene.o: countertablesscene.cpp countertablesscene.h \ + common.h \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + table.h \ + qcustomplot.h \ + statisticsconstants.h \ + animnode.h \ + resizeableitem.h \ + animatorconstants.h \ + animatormode.h \ + animatorscene.h \ + animlink.h \ + timevalue.h \ + animpacket.h \ + animevent.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + statsview.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o countertablesscene.o countertablesscene.cpp + +qcustomplot.o: qcustomplot.cpp qcustomplot.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qcustomplot.o qcustomplot.cpp + +moc_animatorscene.o: moc_animatorscene.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_animatorscene.o moc_animatorscene.cpp + +moc_animpacket.o: moc_animpacket.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_animpacket.o moc_animpacket.cpp + +moc_netanim.o: moc_netanim.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_netanim.o moc_netanim.cpp + +moc_animatormode.o: moc_animatormode.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_animatormode.o moc_animatormode.cpp + +moc_statsmode.o: moc_statsmode.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_statsmode.o moc_statsmode.cpp + +moc_qtpropertybrowserutils_p.o: moc_qtpropertybrowserutils_p.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qtpropertybrowserutils_p.o moc_qtpropertybrowserutils_p.cpp + +moc_animpropertybrowser.o: moc_animpropertybrowser.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_animpropertybrowser.o moc_animpropertybrowser.cpp + +moc_filepathmanager.o: moc_filepathmanager.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_filepathmanager.o moc_filepathmanager.cpp + +moc_fileeditfactory.o: moc_fileeditfactory.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_fileeditfactory.o moc_fileeditfactory.cpp + +moc_fileedit.o: moc_fileedit.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_fileedit.o moc_fileedit.cpp + +moc_packetsmode.o: moc_packetsmode.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_packetsmode.o moc_packetsmode.cpp + +moc_table.o: moc_table.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_table.o moc_table.cpp + +moc_qcustomplot.o: moc_qcustomplot.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_qcustomplot.o moc_qcustomplot.cpp + +qrc_resources.o: qrc_resources.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_resources.o qrc_resources.cpp + +qrc_qtpropertybrowser.o: qrc_qtpropertybrowser.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_qtpropertybrowser.o qrc_qtpropertybrowser.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/ns-3-allinone/netanim/NetAnimOnline.pro b/ns-3-allinone/netanim/NetAnimOnline.pro new file mode 100644 index 0000000..4a3ef26 --- /dev/null +++ b/ns-3-allinone/netanim/NetAnimOnline.pro @@ -0,0 +1,169 @@ +greaterThan(QT_MAJOR_VERSION, 4) { + QT += widgets printsupport +} + +SOURCES += \ + main.cpp \ + log.cpp \ + fatal-error.cpp \ + fatal-impl.cpp \ + logqt.cpp \ + resizeableitem.cpp \ + animnode.cpp \ + animatorscene.cpp \ + animpacket.cpp \ + netanim.cpp \ + animatormode.cpp \ + mode.cpp \ + animxmlparser.cpp \ + animatorview.cpp \ + animlink.cpp \ + animresource.cpp \ + statsview.cpp \ + statsmode.cpp \ + routingxmlparser.cpp \ + routingstatsscene.cpp \ + interfacestatsscene.cpp \ + flowmonxmlparser.cpp \ + flowmonstatsscene.cpp \ + textbubble.cpp \ + qtpropertybrowser/src/qtvariantproperty.cpp \ + qtpropertybrowser/src/qttreepropertybrowser.cpp \ + qtpropertybrowser/src/qtpropertymanager.cpp \ + qtpropertybrowser/src/qtpropertybrowserutils.cpp \ + qtpropertybrowser/src/qtpropertybrowser.cpp \ + qtpropertybrowser/src/qtgroupboxpropertybrowser.cpp \ + qtpropertybrowser/src/qteditorfactory.cpp \ + qtpropertybrowser/src/qtbuttonpropertybrowser.cpp \ + animpropertybrowser.cpp \ + qtpropertybrowser/src/filepathmanager.cpp \ + qtpropertybrowser/src/fileeditfactory.cpp \ + qtpropertybrowser/src/fileedit.cpp \ + packetsmode.cpp \ + packetsview.cpp \ + packetsscene.cpp \ + graphpacket.cpp \ + table.cpp \ + countertablesscene.cpp \ + qcustomplot.cpp +HEADERS += \ + log.h \ + fatal-error.h \ + fatal-impl.h \ + abort.h \ + assert.h \ + logqt.h \ + animatorconstants.h \ + resizeableitem.h \ + animnode.h \ + common.h \ + animatorscene.h \ + timevalue.h \ + animpacket.h \ + netanim.h \ + animatormode.h \ + animatorview.h \ + mode.h \ + animxmlparser.h \ + animevent.h \ + animlink.h \ + animresource.h \ + statsview.h \ + statsmode.h \ + statisticsconstants.h \ + routingxmlparser.h \ + routingstatsscene.h \ + interfacestatsscene.h \ + flowmonxmlparser.h \ + flowmonstatsscene.h \ + textbubble.h \ + qtpropertybrowser/src/QtVariantPropertyManager \ + qtpropertybrowser/src/QtVariantProperty \ + qtpropertybrowser/src/qtvariantproperty.h \ + qtpropertybrowser/src/QtVariantEditorFactory \ + qtpropertybrowser/src/QtTreePropertyBrowser \ + qtpropertybrowser/src/qttreepropertybrowser.h \ + qtpropertybrowser/src/QtTimePropertyManager \ + qtpropertybrowser/src/QtTimeEditFactory \ + qtpropertybrowser/src/QtStringPropertyManager \ + qtpropertybrowser/src/QtSpinBoxFactory \ + qtpropertybrowser/src/QtSliderFactory \ + qtpropertybrowser/src/QtSizePropertyManager \ + qtpropertybrowser/src/QtSizePolicyPropertyManager \ + qtpropertybrowser/src/QtSizeFPropertyManager \ + qtpropertybrowser/src/QtScrollBarFactory \ + qtpropertybrowser/src/QtRectPropertyManager \ + qtpropertybrowser/src/QtRectFPropertyManager \ + qtpropertybrowser/src/qtpropertymanager.h \ + qtpropertybrowser/src/qtpropertybrowserutils_p.h \ + qtpropertybrowser/src/qtpropertybrowser.h \ + qtpropertybrowser/src/QtProperty \ + qtpropertybrowser/src/QtPointPropertyManager \ + qtpropertybrowser/src/QtPointFPropertyManager \ + qtpropertybrowser/src/QtLocalePropertyManager \ + qtpropertybrowser/src/QtLineEditFactory \ + qtpropertybrowser/src/QtKeySequencePropertyManager \ + qtpropertybrowser/src/QtKeySequenceEditorFactory \ + qtpropertybrowser/src/QtIntPropertyManager \ + qtpropertybrowser/src/QtGroupPropertyManager \ + qtpropertybrowser/src/QtGroupBoxPropertyBrowser \ + qtpropertybrowser/src/qtgroupboxpropertybrowser.h \ + qtpropertybrowser/src/QtFontPropertyManager \ + qtpropertybrowser/src/QtFontEditorFactory \ + qtpropertybrowser/src/QtFlagPropertyManager \ + qtpropertybrowser/src/QtEnumPropertyManager \ + qtpropertybrowser/src/QtEnumEditorFactory \ + qtpropertybrowser/src/qteditorfactory.h \ + qtpropertybrowser/src/QtDoubleSpinBoxFactory \ + qtpropertybrowser/src/QtDoublePropertyManager \ + qtpropertybrowser/src/QtDateTimePropertyManager \ + qtpropertybrowser/src/QtDateTimeEditFactory \ + qtpropertybrowser/src/QtDatePropertyManager \ + qtpropertybrowser/src/QtDateEditFactory \ + qtpropertybrowser/src/QtCursorPropertyManager \ + qtpropertybrowser/src/QtCursorEditorFactory \ + qtpropertybrowser/src/QtColorPropertyManager \ + qtpropertybrowser/src/QtColorEditorFactory \ + qtpropertybrowser/src/QtCheckBoxFactory \ + qtpropertybrowser/src/QtCharPropertyManager \ + qtpropertybrowser/src/QtCharEditorFactory \ + qtpropertybrowser/src/QtButtonPropertyBrowser \ + qtpropertybrowser/src/qtbuttonpropertybrowser.h \ + qtpropertybrowser/src/QtBrowserItem \ + qtpropertybrowser/src/QtBoolPropertyManager \ + qtpropertybrowser/src/QtAbstractPropertyManager \ + qtpropertybrowser/src/QtAbstractPropertyBrowser \ + qtpropertybrowser/src/QtAbstractEditorFactoryBase \ + animpropertybrowser.h \ + qtpropertybrowser/src/filepathmanager.h \ + qtpropertybrowser/src/fileeditfactory.h \ + qtpropertybrowser/src/fileedit.h \ + packetsmode.h \ + packetsview.h \ + packetsscene.h \ + graphpacket.h \ + table.h \ + countertablesscene.h \ + qcustomplot.h + +TEMPLATE = lib + +INCLUDEPATH += qtpropertybrowser/src +INCLUDEPATH += /usr/local/include/ns3-dev +DEFINES += NS3_LOG_ENABLE + +QMAKE_CXXFLAGS += -std=c++11 +QMAKE_LFLAGS += -Wl,-rpath=\'\$\$ORIGIN\' -Wl,-rpath-link=\'\$\$ORIGIN\' -Wl,-z,origin -lc + +RESOURCES += \ + resources.qrc \ + qtpropertybrowser/src/qtpropertybrowser.qrc + +OTHER_FILES += \ + qtpropertybrowser/src/qtpropertybrowser.pri + +macx { + CONFIG -= app_bundle + QMAKESPEC = macx-g++ +} + diff --git a/ns-3-allinone/netanim/animatormode.h b/ns-3-allinone/netanim/animatormode.h index c5b0b14..587e40c 100644 --- a/ns-3-allinone/netanim/animatormode.h +++ b/ns-3-allinone/netanim/animatormode.h @@ -27,9 +27,10 @@ #include "animatorscene.h" #include "animatorview.h" #include "mode.h" +#include "animxmlparser.h" #include "timevalue.h" #include "animevent.h" -#include "QtTreePropertyBrowser" +// #include "QtTreePropertyBrowser" namespace netanim { @@ -53,6 +54,7 @@ class AnimatorMode: public Mode // Getters static AnimatorMode * getInstance (); + Animxmlparser * getAnimxmlparser(); //Online mode QWidget * getCentralWidget (); QString getTabName (); qreal getCurrentNodeSize (); @@ -61,6 +63,7 @@ class AnimatorMode: public Mode qreal getLastPacketEventTime (); qreal getThousandthPacketTime (); qreal getFirstPacketTime (); + bool getOnlineMode();//Online mode // Setters @@ -77,6 +80,8 @@ class AnimatorMode: public Mode void setShowNodeTrajectory (AnimNode * animNode); void setBackgroundImageProperties (BackgroudImageProperties_t prop); BackgroudImageProperties_t getBackgroundProperties (); + void setOnlineMode (bool mode); //Online mode + // void setEventsOver (bool isOver); // Actions @@ -85,6 +90,7 @@ class AnimatorMode: public Mode void externalPauseEvent (); void start (); void openPropertyBroswer (); + bool parseOnline (); //Online mode private: @@ -99,6 +105,7 @@ class AnimatorMode: public Mode PAUSING, SIMULATION_COMPLETE } AnimatorModeState_t; + Animxmlparser * m_animxmlparser; //Online mode double m_version; bool m_playing; AnimatorModeState_t m_state; @@ -130,9 +137,9 @@ class AnimatorMode: public Mode QPointF m_minPoint; QPointF m_maxPoint; bool m_backgroundExists; - - - + bool m_onlineMode; //Online mode + bool m_eventObtained; //Online mode + qreal m_nextTs; //Online mode //controls QVBoxLayout * m_vLayout; @@ -189,6 +196,7 @@ class AnimatorMode: public Mode //functions AnimatorMode (); + ~AnimatorMode (); bool parseXMLTraceFile (QString traceFileName); void setLabelStyleSheet (); void initUpdateRate (); @@ -227,6 +235,7 @@ class AnimatorMode: public Mode QPropertyAnimation * getButtonAnimation (QToolButton * toolButton); void initPropertyBrowser (); void removeWiredPacket (AnimPacket * animPacket); + qreal getTimeFromSimulator (void); private slots: diff --git a/ns-3-allinone/netanim/animxmlparser.cpp b/ns-3-allinone/netanim/animxmlparser.cpp index 5fe46fd..0003925 100755 --- a/ns-3-allinone/netanim/animxmlparser.cpp +++ b/ns-3-allinone/netanim/animxmlparser.cpp @@ -81,118 +81,20 @@ Animxmlparser::~Animxmlparser () } void -Animxmlparser::searchForVersion () -{ - QFile * f = new QFile (m_traceFileName); - if (f->open (QIODevice::ReadOnly | QIODevice::Text)) - { - QString firstLine = QString (f->readLine ()); - int startIndex = 0; - int endIndex = 0; - QString versionField = VERSION_FIELD_DEFAULT; - startIndex = firstLine.indexOf (versionField); - endIndex = firstLine.lastIndexOf ("\""); - if ((startIndex != -1) && (endIndex > startIndex)) - { - int adjustedStartIndex = startIndex + versionField.length (); - QString v = firstLine.mid (adjustedStartIndex, endIndex-adjustedStartIndex); - m_version = v.toDouble (); - } - f->close (); - delete f; - } -} - -uint64_t -Animxmlparser::getRxCount () -{ - searchForVersion (); - uint64_t count = 1; - QFile * f = new QFile (m_traceFileName); - if (f->open (QIODevice::ReadOnly | QIODevice::Text)) - { - QString allContent = QString (f->readAll ()); - int j = 0; - QString searchString = " toId="; - if (m_version >= 3.102) - searchString = " tId"; - - while ( (j = allContent.indexOf (searchString, j)) != -1) - { - ++j; - ++count; - } - f->close (); - delete f; - //qDebug (QString::number (count)); - } - return qMax (count, (uint64_t)1); -} - -bool -Animxmlparser::isFileValid () +Animxmlparser::doParse(ParsedElement parsedElement) { - return m_fileIsValid; -} - -bool -Animxmlparser::isParsingComplete () -{ - return m_parsingComplete; -} - -qreal -Animxmlparser::getLastPacketEventTime () -{ - return m_lastPacketEventTime; -} - -qreal -Animxmlparser::getFirstPacketTime () -{ - return m_firstPacketTime; -} - -QPointF -Animxmlparser::getMinPoint () -{ - return QPointF (m_minNodeX, m_minNodeY); -} - -QPointF -Animxmlparser::getMaxPoint () -{ - return QPointF (m_maxNodeX, m_maxNodeY); -} - -qreal -Animxmlparser::getThousandthPacketTime () -{ - return m_thousandThPacketTime; -} - -void -Animxmlparser::doParse () -{ - uint64_t parsedElementCount = 0; + NS_LOG_DEBUG("doParse of parsed element"); AnimatorMode * pAnimatorMode = AnimatorMode::getInstance (); - while (!isParsingComplete ()) - { - if (AnimatorMode::getInstance ()->keepAppResponsive ()) - { - AnimatorMode::getInstance ()->setParsingCount (parsedElementCount); - } - ParsedElement parsedElement = parseNext (); - switch (parsedElement.type) - { - case XML_ANIM: + switch (parsedElement.type) + { + case XML_ANIM: { AnimatorMode::getInstance ()->setVersion (parsedElement.version); //qDebug (QString ("XML Version:") + QString::number (version)); break; } - case XML_NODE: + case XML_NODE: { m_minNodeX = qMin (m_minNodeX, parsedElement.node_x); m_minNodeY = qMin (m_minNodeY, parsedElement.node_y); @@ -405,8 +307,116 @@ Animxmlparser::doParse () { //qDebug ("Invalid XML element"); } - } //switch - } // while loop + + } +} + +void +Animxmlparser::searchForVersion () +{ + QFile * f = new QFile (m_traceFileName); + if (f->open (QIODevice::ReadOnly | QIODevice::Text)) + { + QString firstLine = QString (f->readLine ()); + int startIndex = 0; + int endIndex = 0; + QString versionField = VERSION_FIELD_DEFAULT; + startIndex = firstLine.indexOf (versionField); + endIndex = firstLine.lastIndexOf ("\""); + if ((startIndex != -1) && (endIndex > startIndex)) + { + int adjustedStartIndex = startIndex + versionField.length (); + QString v = firstLine.mid (adjustedStartIndex, endIndex-adjustedStartIndex); + m_version = v.toDouble (); + } + f->close (); + delete f; + } +} + +uint64_t +Animxmlparser::getRxCount () +{ + searchForVersion (); + uint64_t count = 1; + QFile * f = new QFile (m_traceFileName); + if (f->open (QIODevice::ReadOnly | QIODevice::Text)) + { + QString allContent = QString (f->readAll ()); + int j = 0; + QString searchString = " toId="; + if (m_version >= 3.102) + searchString = " tId"; + + while ( (j = allContent.indexOf (searchString, j)) != -1) + { + ++j; + ++count; + } + f->close (); + delete f; + //qDebug (QString::number (count)); + } + return qMax (count, (uint64_t)1); +} + +bool +Animxmlparser::isFileValid () +{ + return m_fileIsValid; +} + +bool +Animxmlparser::isParsingComplete () +{ + return m_parsingComplete; +} + +qreal +Animxmlparser::getLastPacketEventTime () +{ + return m_lastPacketEventTime; +} + +qreal +Animxmlparser::getFirstPacketTime () +{ + return m_firstPacketTime; +} + +QPointF +Animxmlparser::getMinPoint () +{ + return QPointF (m_minNodeX, m_minNodeY); +} + +QPointF +Animxmlparser::getMaxPoint () +{ + return QPointF (m_maxNodeX, m_maxNodeY); +} + +qreal +Animxmlparser::getThousandthPacketTime () +{ + return m_thousandThPacketTime; +} + +void +Animxmlparser::doParse () +{ + NS_LOG_DEBUG("doParse"); + parsedElementCount = 0; + // AnimatorMode * pAnimatorMode = AnimatorMode::getInstance (); + while (!isParsingComplete ()) + { + if (AnimatorMode::getInstance ()->keepAppResponsive ()) + { + AnimatorMode::getInstance ()->setParsingCount (parsedElementCount); + } + ParsedElement parsedElement = parseNext (); + doParse(parsedElement); + } } ParsedElement diff --git a/ns-3-allinone/netanim/animxmlparser.h b/ns-3-allinone/netanim/animxmlparser.h index 495e14d..c37fb7a 100755 --- a/ns-3-allinone/netanim/animxmlparser.h +++ b/ns-3-allinone/netanim/animxmlparser.h @@ -165,6 +165,7 @@ class Animxmlparser void setMaxSimulationTime (qreal t); bool isFileValid (); uint64_t getRxCount (); + void doParse(ParsedElement parsedelement); //Online Mode void doParse (); qreal getLastPacketEventTime (); qreal getThousandthPacketTime (); @@ -185,6 +186,8 @@ class Animxmlparser qreal m_thousandThPacketTime; qreal m_firstPacketTime; + uint64_t parsedElementCount; + qreal m_minNodeX; qreal m_minNodeY; qreal m_maxNodeX; diff --git a/ns-3-allinone/netanim/fatal-error.h b/ns-3-allinone/netanim/fatal-error.h index 1f3fb6b..f6b0417 100644 --- a/ns-3-allinone/netanim/fatal-error.h +++ b/ns-3-allinone/netanim/fatal-error.h @@ -28,53 +28,154 @@ #include "fatal-impl.h" /** - * \ingroup debugging - * \brief fatal error handling + * \file + * \ingroup fatal + * \brief \c NS_FATAL_x macro definitions. + */ + +/** + * \ingroup core + * \defgroup fatal Fatal Error Handlers * - * When this macro is hit at runtime, details of filename - * and line number is printed to stderr, and the program - * is halted by calling std::terminate(). This will - * trigger any clean up code registered by - * std::set_terminate (NS3 default is a stream-flushing - * code), but may be overridden. + * \brief Functions to help clean up when a fatal error + * is encountered. + * + * The functions in this group are used to perform + * limited clean up, like flushing active streams, when + * fatal errors are encountered (through assertion fail, + * calls to NS_ABORT_* or calls to NS_FATAL_ERROR). + * + * Currently, other than flushing active ostreams, these + * functions does not interfere with outside memory. There + * is still a residual risk that invalid ostream + * pointers may be present, and may corrupt the memory + * on the attempt to execute the flush() function. + */ + +/** + * \ingroup fatal + * + * \brief Fatal error reporting with no message, implementation. + * + * When this macro is hit at runtime the error details will + * printed to \c stderr, including the file name and line number. + * Optionally, if \c fatal is true, the macro + * will invoke \c std::terminate(). If \c fatal is false, + * the invoking function should return an error code to its caller, + * which is expected to call NS_FATAL_ERROR to cause termination. + * + * \param [in] fatal Call \c std::terminate() if true. * * This macro is enabled unconditionally in all builds, * including debug and optimized builds. */ -#define NS_FATAL_ERROR_NO_MSG() \ +#define NS_FATAL_ERROR_IMPL_NO_MSG(fatal) \ do \ { \ std::cerr << "file=" << __FILE__ << ", line=" << \ - __LINE__ << std::endl; \ + __LINE__ << std::endl; \ ::ns3::FatalImpl::FlushStreams (); \ - std::terminate (); \ + if (fatal) std::terminate (); \ } \ while (false) + /** - * \ingroup debugging - * \brief fatal error handling + * \ingroup fatal * - * \param msg message to output when this macro is hit. + * \brief Fatal error reporting with a message, implementation. * - * When this macro is hit at runtime, the user-specified - * error message is printed to stderr, followed by a call - * to the NS_FATAL_ERROR_NO_MSG() macro which prints the - * details of filename and line number to stderr. The - * program will be halted by calling std::terminate(), - * triggering any clean up code registered by - * std::set_terminate (NS3 default is a stream-flushing - * code, but may be overridden). + * When this macro is hit at runtime the error details will + * printed to \c stderr, including the message, file name and line number. + * Optionally, if \c fatal is true, the macro + * will invoke \c std::terminate(). If \c fatal is false, + * the invoking function should return an error code to its caller, + * which is expected to call NS_FATAL_ERROR to cause termination. + * + * \param [in] msg The error message to print, if not empty. + * \param [in] fatal Call \c std::terminate() if true. * * This macro is enabled unconditionally in all builds, * including debug and optimized builds. */ -#define NS_FATAL_ERROR(msg) \ +#define NS_FATAL_ERROR_IMPL(msg,fatal) \ do \ { \ std::cerr << "msg=\"" << msg << "\", "; \ - NS_FATAL_ERROR_NO_MSG (); \ + NS_FATAL_ERROR_IMPL_NO_MSG (fatal); \ } \ while (false) -#endif /* FATAL_ERROR_H */ + +/** + * \ingroup fatal + * + * \brief Report a fatal error and terminate. + * + * When this macro is hit at runtime, details of filename + * and line number are printed to \c stderr, and the program + * is halted by calling \c std::terminate(). This will + * trigger any clean up code registered by + * \c std::set_terminate (NS3 default is a stream-flushing + * code), but may be overridden. + * + * This macro is enabled unconditionally in all builds, + * including debug and optimized builds. + */ +#define NS_FATAL_ERROR_NO_MSG() NS_FATAL_ERROR_IMPL_NO_MSG (true) + +/** + * \ingroup fatal + * + * \brief Report a fatal error, deferring termination. + * + * When this macro is hit at runtime, details of filename + * and line number are printed to \c stderr, however the program + * is _not_ halted. It is expected that the function using this + * macro will return an error code, and its caller will + * invoke NS_FATAL_ERROR(msg) triggering std::terminate(). + * + * This macro is enabled unconditionally in all builds, + * including debug and optimized builds. + */ +#define NS_FATAL_ERROR_NO_MSG_CONT() NS_FATAL_ERROR_IMPL_NO_MSG (false) + +/** + * \ingroup fatal + * + * \brief Report a fatal error with a message and terminate. + * + * \param [in] msg message to output when this macro is hit. + * + * When this macro is hit at runtime, the user-specified + * error message are printed to \c stderr, followed by a call + * to the NS_FATAL_ERROR_NO_MSG() macro which prints the + * details of filename and line number to \c stderr. The + * program will be halted by calling \c std::terminate(), + * triggering any clean up code registered by + * \c std::set_terminate (NS3 default is a stream-flushing + * code, but may be overridden). + * + * This macro is enabled unconditionally in all builds, + * including debug and optimized builds. + */ +#define NS_FATAL_ERROR(msg) NS_FATAL_ERROR_IMPL (msg, true) + +/** + * \ingroup fatal + * + * \brief Report a fatal error with a message, deferring termination. + * + * When this macro is hit at runtime, details of filename + * and line number are printed to \c stderr, however the program + * is _not_ halted. It is expected that the function using this + * macro will return an error code, and its caller will + * invoke NS_FATAL_ERROR(msg) triggering \c std::terminate(). + * + * This macro is enabled unconditionally in all builds, + * including debug and optimized builds. + */ +#define NS_FATAL_ERROR_CONT(msg) NS_FATAL_ERROR_IMPL (msg, false) + + +#endif /* FATAL_ERROR_H */ \ No newline at end of file diff --git a/ns-3-allinone/netanim/log.cpp b/ns-3-allinone/netanim/log.cpp index 0fdad81..3b48970 100644 --- a/ns-3-allinone/netanim/log.cpp +++ b/ns-3-allinone/netanim/log.cpp @@ -554,7 +554,7 @@ static void CheckEnvironmentVariables (void) "\" in env variable NS_LOG, see above for a list of valid components"); } } - cur = next + 1; // parse next component + cur = next + 1; // parse next component } #endif } @@ -585,4 +585,4 @@ ParameterLogger::ParameterLogger (std::ostream &os) { } -} // namespace ns3 +} // namespace ns3 \ No newline at end of file diff --git a/ns-3-allinone/netanim/netanim.cpp b/ns-3-allinone/netanim/netanim.cpp index 0e1aa6a..db9e7c6 100644 --- a/ns-3-allinone/netanim/netanim.cpp +++ b/ns-3-allinone/netanim/netanim.cpp @@ -26,7 +26,7 @@ namespace netanim { -NetAnim::NetAnim (): +NetAnim::NetAnim (bool OnlineMode): m_tabWidget (new QTabWidget) { @@ -55,6 +55,7 @@ NetAnim::NetAnim (): m_tabWidget->setGeometry (0, 0, minimumDimension, minimumDimension); m_tabWidget->showMaximized (); m_tabWidget->show (); + animatorTab->setOnlineMode(OnlineMode); animatorTab->start (); } diff --git a/ns-3-allinone/netanim/netanim.h b/ns-3-allinone/netanim/netanim.h index 7a80b20..c678251 100644 --- a/ns-3-allinone/netanim/netanim.h +++ b/ns-3-allinone/netanim/netanim.h @@ -29,7 +29,7 @@ class NetAnim : public QObject { Q_OBJECT public: - NetAnim (); + NetAnim (bool OnlineMode = false); QTabWidget * getTabWidget(); private: typedef std::map TabIndexModeMap_t; diff --git a/ns-3-allinone/netanim/timevalue.h b/ns-3-allinone/netanim/timevalue.h index ed714ea..8d32eda 100644 --- a/ns-3-allinone/netanim/timevalue.h +++ b/ns-3-allinone/netanim/timevalue.h @@ -1,4 +1,4 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -59,6 +59,7 @@ class TimeValue T get (qreal tUpperBound, TimeValueResult_t & result); TimeValueIteratorPair_t getRange (qreal lowerBound, qreal upperBound); TimeValueIteratorPair_t getNext (TimeValueResult_t & result); + void getNextGOOD (TimeValueResult_t & result); std::string toString (); void setLookBack (qreal lookBack); bool isEnd (); @@ -211,6 +212,19 @@ TimeValue::getNext (TimeValueResult_t & result) } +//Online Mode +template +void +TimeValue::getNextGOOD (TimeValueResult_t & result) +{ + result = GOOD; + TimeValueIteratorPair_t pp = m_timeValues.equal_range (m_getIterator->first); + if (m_getIterator == m_timeValues.end ()) + { + result = OVERRUN; + } +} + template T TimeValue::get (qreal tUpperBound, TimeValueResult_t & result) diff --git a/ns-3-allinone/ns-3-dev/log b/ns-3-allinone/ns-3-dev/log new file mode 100644 index 0000000..3616f84 --- /dev/null +++ b/ns-3-allinone/ns-3-dev/log @@ -0,0 +1 @@ +update2 1.84467e+10 diff --git a/ns-3-allinone/ns-3-dev/scratch/first.cc b/ns-3-allinone/ns-3-dev/scratch/first.cc new file mode 100644 index 0000000..1fd579f --- /dev/null +++ b/ns-3-allinone/ns-3-dev/scratch/first.cc @@ -0,0 +1,76 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/netanim-module.h" +#include "ns3/point-to-point-module.h" +#include "ns3/applications-module.h" + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); + +int +main (int argc, char *argv[]) +{ + CommandLine cmd; + cmd.Parse (argc, argv); + + Time::SetResolution (Time::NS); + // LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); + // LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); + + NodeContainer nodes; + nodes.Create (2); + + PointToPointHelper pointToPoint; + pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); + pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); + + NetDeviceContainer devices; + devices = pointToPoint.Install (nodes); + + InternetStackHelper stack; + stack.Install (nodes); + + Ipv4AddressHelper address; + address.SetBase ("10.1.1.0", "255.255.255.0"); + + Ipv4InterfaceContainer interfaces = address.Assign (devices); + + UdpEchoServerHelper echoServer (9); + + ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); + serverApps.Start (Seconds (1.0)); + serverApps.Stop (Seconds (10.0)); + + UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); + echoClient.SetAttribute ("MaxPackets", UintegerValue (1)); + echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); + echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); + + ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); + clientApps.Start (Seconds (2.0)); + clientApps.Stop (Seconds (10.0)); + // std::string animFile = "first.xml"; + AnimationInterface anim; + + Simulator::Run (); + Simulator::Destroy (); + return 0; +} diff --git a/ns-3-allinone/ns-3-dev/scratch/grid-animation.cc b/ns-3-allinone/ns-3-dev/scratch/grid-animation.cc index 2432d18..239d04b 100644 --- a/ns-3-allinone/ns-3-dev/scratch/grid-animation.cc +++ b/ns-3-allinone/ns-3-dev/scratch/grid-animation.cc @@ -30,6 +30,9 @@ using namespace ns3; int main (int argc, char *argv[]) { + freopen("out.txt","w", stderr); + LogComponentEnableAll (LOG_LEVEL_ALL); + Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512)); Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s")); @@ -69,6 +72,7 @@ int main (int argc, char *argv[]) clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); ApplicationContainer clientApps; + // Create an on/off app sending packets AddressValue remoteAddress (InetSocketAddress (grid.GetIpv4Address (xSize-1,ySize-1), 1000)); clientHelper.SetAttribute ("Remote", remoteAddress); @@ -81,10 +85,10 @@ int main (int argc, char *argv[]) grid.BoundingBox (1, 1, 100, 100); // Create the animation object and configure for specified output - AnimationInterface anim (animFile); + Ipv4GlobalRoutingHelper::PopulateRoutingTables (); + AnimationInterface anim; // Set up the actual simulation - Ipv4GlobalRoutingHelper::PopulateRoutingTables (); Simulator::Run (); Simulator::Destroy (); diff --git a/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.cc b/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.cc index ba0609a..db4644a 100644 --- a/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.cc +++ b/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.cc @@ -30,7 +30,7 @@ #include - +// #include "animatormode.h" /** * \file * \ingroup simulator @@ -41,11 +41,14 @@ namespace ns3 { // Note: Logging in this file is largely avoided due to the // number of calls that are made to these functions and the possibility -// of causing recursions leading to stack overflow +// of causing recursions leading r stack overflow NS_LOG_COMPONENT_DEFINE ("DefaultSimulatorImpl"); NS_OBJECT_ENSURE_REGISTERED (DefaultSimulatorImpl); +bool DefaultSimulatorImpl::m_isOnline = false; +uint64_t DefaultSimulatorImpl::m_nextTs = -1; + TypeId DefaultSimulatorImpl::GetTypeId (void) { @@ -80,6 +83,12 @@ DefaultSimulatorImpl::~DefaultSimulatorImpl () NS_LOG_FUNCTION (this); } +uint64_t +DefaultSimulatorImpl::getNextTs (void) +{ + return m_nextTs; +} + void DefaultSimulatorImpl::DoDispose (void) { @@ -94,6 +103,7 @@ DefaultSimulatorImpl::DoDispose (void) m_events = 0; SimulatorImpl::DoDispose (); } + void DefaultSimulatorImpl::Destroy () { @@ -127,6 +137,18 @@ DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory) m_events = scheduler; } +void +DefaultSimulatorImpl::setOnlineMode (bool mode) +{ + m_isOnline = mode; +} + +bool +DefaultSimulatorImpl::getOnlineMode () +{ + return m_isOnline; +} + // System ID for non-distributed simulation is always zero uint32_t DefaultSimulatorImpl::GetSystemId (void) const @@ -152,12 +174,60 @@ DefaultSimulatorImpl::ProcessOneEvent (void) ProcessEventsWithContext (); } +void +DefaultSimulatorImpl::ProcessElementsWithSameTime (void) +{ + m_isOnline = -1; + if (!m_events->IsEmpty ()) + { + Scheduler::Event first = m_events->RemoveNext (); + // Scheduler::Event current = first; + m_currentTs = first.key.m_ts; + m_unscheduledEvents--; + m_currentContext = first.key.m_context; + m_currentUid = first.key.m_uid; + first.impl->Invoke (); + first .impl->Unref (); + + ProcessEventsWithContext (); + NS_LOG_DEBUG(first.key.m_ts); + while (!m_events->IsEmpty ()) + { + Scheduler::Event current = m_events->RemoveNext (); + if (current.key.m_ts > m_currentTs) + { + m_nextTs = current.key.m_ts; + m_events->Insert (current); + return; + } + m_currentTs = current.key.m_ts; + m_unscheduledEvents--; + NS_LOG_LOGIC ("handle " << current.key.m_ts); + + m_currentContext = current.key.m_context; + m_currentUid = current.key.m_uid; + current.impl->Invoke (); + current.impl->Unref (); + + ProcessEventsWithContext (); + } + + + } +} + + bool DefaultSimulatorImpl::IsFinished (void) const { return m_events->IsEmpty () || m_stop; } +/*bool +DefaultSimulatorImpl::getmEvents (void){ + return m_events->IsEmpty(); +}*/ + void DefaultSimulatorImpl::ProcessEventsWithContext (void) { @@ -188,23 +258,38 @@ DefaultSimulatorImpl::ProcessEventsWithContext (void) } } +/*void setStartClock (struct timeval * startClock) +{ + gettimeofday (startClock, 0); +} +*/ void DefaultSimulatorImpl::Run (void) { NS_LOG_FUNCTION (this); // Set the current threadId as the main threadId - m_main = SystemThread::Self(); - ProcessEventsWithContext (); - m_stop = false; - while (!m_events->IsEmpty () && !m_stop) - { - ProcessOneEvent (); - } + if(!m_isOnline) + { + m_main = SystemThread::Self(); + ProcessEventsWithContext (); + m_stop = false; + + while (!m_events->IsEmpty () && !m_stop) + { + ProcessOneEvent (); + } + // If the simulator stopped naturally by lack of events, make a + // consistency test to check that we didn't lose any events along the way. + NS_ASSERT (!m_events->IsEmpty () || m_unscheduledEvents == 0); + } + else + { + ProcessEventsWithContext (); + m_stop = false; - // If the simulator stopped naturally by lack of events, make a - // consistency test to check that we didn't lose any events along the way. - NS_ASSERT (!m_events->IsEmpty () || m_unscheduledEvents == 0); + ProcessElementsWithSameTime (); + } } void @@ -409,9 +494,10 @@ DefaultSimulatorImpl::GetMaximumSimulationTime (void) const } uint32_t -DefaultSimulatorImpl::GetContext (void) const +DefaultSimulatorImpl::GetContext () const { return m_currentContext; } } // namespace ns3 + diff --git a/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.h b/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.h index aa4ce10..4f189ec 100644 --- a/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.h +++ b/ns-3-allinone/ns-3-dev/src/core/model/default-simulator-impl.h @@ -30,7 +30,6 @@ #include "ptr.h" #include - /** * \file * \ingroup simulator @@ -78,11 +77,17 @@ class DefaultSimulatorImpl : public SimulatorImpl virtual uint32_t GetSystemId (void) const; virtual uint32_t GetContext (void) const; + //OnlineMode + static void setOnlineMode (bool mode); + static bool getOnlineMode (void); + static uint64_t getNextTs (void); + // static bool getmEvents (void); private: virtual void DoDispose (void); /** Process the next event. */ void ProcessOneEvent (void); + void ProcessElementsWithSameTime (void); //OnlineMode /** Move events from a different context into the main event queue. */ void ProcessEventsWithContext (void); @@ -120,7 +125,7 @@ class DefaultSimulatorImpl : public SimulatorImpl uint32_t m_uid; /** Unique id of the current event. */ uint32_t m_currentUid; - /** Timestamp of the current event. */ + // * Timestamp of the current event. uint64_t m_currentTs; /** Execution context of the current event. */ uint32_t m_currentContext; @@ -132,8 +137,13 @@ class DefaultSimulatorImpl : public SimulatorImpl /** Main execution thread. */ SystemThread::ThreadId m_main; + + // uint64_t currentTs; + static uint64_t m_nextTs; + static bool m_isOnline; //Online Mode + }; } // namespace ns3 -#endif /* DEFAULT_SIMULATOR_IMPL_H */ +#endif /* DEFAULT_SIMULATOR_IMPL_H */ \ No newline at end of file diff --git a/ns-3-allinone/ns-3-dev/src/core/model/log.cc b/ns-3-allinone/ns-3-dev/src/core/model/log.cc index 06a76f5..299d1f9 100644 --- a/ns-3-allinone/ns-3-dev/src/core/model/log.cc +++ b/ns-3-allinone/ns-3-dev/src/core/model/log.cc @@ -23,7 +23,6 @@ #include #include #include "assert.h" -#include #include "ns3/core-config.h" #include "fatal-error.h" @@ -131,23 +130,6 @@ LogComponent::LogComponent (const std::string & name, components->insert (std::make_pair (name, this)); } -LogComponent & -GetLogComponent (const std::string name) -{ - LogComponent::ComponentList *components = LogComponent::GetComponentList (); - LogComponent* ret; - - try - { - ret = components->at (name); - } - catch (std::out_of_range&) - { - NS_FATAL_ERROR ("Log component \"" << name << "\" does not exist."); - } - return *ret; -} - void LogComponent::EnvVarCheck (void) { diff --git a/ns-3-allinone/ns-3-dev/src/core/model/log.h b/ns-3-allinone/ns-3-dev/src/core/model/log.h index 62ebbc1..b2b2de9 100644 --- a/ns-3-allinone/ns-3-dev/src/core/model/log.h +++ b/ns-3-allinone/ns-3-dev/src/core/model/log.h @@ -212,39 +212,6 @@ void LogComponentDisableAll (enum LogLevel level); #define NS_LOG_COMPONENT_DEFINE_MASK(name, mask) \ static ns3::LogComponent g_log = ns3::LogComponent (name, __FILE__, mask) -/** - * Declare a reference to a Log component. - * - * This macro should be used in the declaration of template classes - * to allow their methods (defined in an header file) to make use of - * the NS_LOG_* macros. This macro should be used in the private - * section to prevent subclasses from using the same log component - * as the base class. - */ -#define NS_LOG_TEMPLATE_DECLARE LogComponent & g_log - -/** - * Initialize a reference to a Log component. - * - * This macro should be used in the constructor of template classes - * to allow their methods (defined in an header file) to make use of - * the NS_LOG_* macros. - * - * \param [in] name The log component name. - */ -#define NS_LOG_TEMPLATE_DEFINE(name) g_log (GetLogComponent (name)) - -/** - * Declare and initialize a reference to a Log component. - * - * This macro should be used in static template methods to allow their - * methods (defined in an header file) to make use of the NS_LOG_* macros. - * - * \param [in] name The log component name. - */ -#define NS_LOG_STATIC_TEMPLATE_DEFINE(name) \ - static LogComponent & NS_UNUSED_GLOBAL (g_log) = GetLogComponent (name) - /** * Use \ref NS_LOG to output a message of level LOG_ERROR. * @@ -442,14 +409,7 @@ class LogComponent }; // class LogComponent -/** - * Get the LogComponent registered with the given name. - * - * \param [in] name The name of the LogComponent. - * \return a reference to the requested LogComponent - */ -LogComponent & GetLogComponent (const std::string name); - + /** * Insert `, ` when streaming function arguments. */ diff --git a/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.cc b/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.cc index 7ed3a39..ca0362f 100644 --- a/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.cc +++ b/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.cc @@ -1,2907 +1,3569 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: George F. Riley - * Modified by: John Abraham - * Contributions: Eugene Kalishenko (Open Source and Linux Laboratory http://dev.osll.ru/) - * Tommaso Pecorella - * Pavel Vasilyev - */ - -// Interface between ns-3 and the network animator - - - -#include -#ifndef WIN32 -#include -#endif -#include -#include -#include -#include -#include - -// ns3 includes -#include "ns3/animation-interface.h" -#include "ns3/channel.h" -#include "ns3/config.h" -#include "ns3/node.h" -#include "ns3/mobility-model.h" -#include "ns3/packet.h" -#include "ns3/simulator.h" -#include "ns3/wifi-mac-header.h" -#include "ns3/wimax-mac-header.h" -#include "ns3/wifi-net-device.h" -#include "ns3/wifi-mac.h" -#include "ns3/lr-wpan-mac-header.h" -#include "ns3/lr-wpan-net-device.h" -#include "ns3/constant-position-mobility-model.h" -#include "ns3/lte-ue-phy.h" -#include "ns3/lte-enb-phy.h" -#include "ns3/uan-net-device.h" -#include "ns3/uan-mac.h" -#include "ns3/double.h" -#include "ns3/ipv4.h" -#include "ns3/ipv6.h" -#include "ns3/ipv4-routing-protocol.h" -#include "ns3/energy-source-container.h" -#include "animation-interface.h" - -namespace ns3 { - -NS_LOG_COMPONENT_DEFINE ("AnimationInterface"); - -// Globals - -static bool initialized = false; //!< Initialization flag - - -// Public methods - -AnimationInterface::AnimationInterface (const std::string fn) - : m_f (0), - m_routingF (0), - m_mobilityPollInterval (Seconds (0.25)), - m_outputFileName (fn), - gAnimUid (0), - m_writeCallback (0), - m_started (false), - m_enablePacketMetadata (false), - m_startTime (Seconds (0)), - m_stopTime (Seconds (3600 * 1000)), - m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE), - m_originalFileName (fn), - m_routingStopTime (Seconds (0)), - m_routingFileName (""), - m_routingPollInterval (Seconds (5)), - m_trackPackets (true) -{ - initialized = true; - StartAnimation (); -} - -AnimationInterface::~AnimationInterface () -{ - StopAnimation (); -} - -void -AnimationInterface::SkipPacketTracing () -{ - m_trackPackets = false; -} - -void -AnimationInterface::EnableWifiPhyCounters (Time startTime, Time stopTime, Time pollInterval) -{ - m_wifiPhyCountersStopTime = stopTime; - m_wifiPhyCountersPollInterval = pollInterval; - m_wifiPhyTxDropCounterId = AddNodeCounter ("WifiPhy TxDrop", AnimationInterface::DOUBLE_COUNTER); - m_wifiPhyRxDropCounterId = AddNodeCounter ("WifiPhy RxDrop", AnimationInterface::DOUBLE_COUNTER); - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - m_nodeWifiPhyTxDrop[n->GetId ()] = 0; - m_nodeWifiPhyRxDrop[n->GetId ()] = 0; - UpdateNodeCounter (m_wifiPhyTxDropCounterId, n->GetId (), 0); - UpdateNodeCounter (m_wifiPhyRxDropCounterId, n->GetId (), 0); - } - Simulator::Schedule (startTime, &AnimationInterface::TrackWifiPhyCounters, this); - -} - -void -AnimationInterface::EnableWifiMacCounters (Time startTime, Time stopTime, Time pollInterval) -{ - m_wifiMacCountersStopTime = stopTime; - m_wifiMacCountersPollInterval = pollInterval; - m_wifiMacTxCounterId = AddNodeCounter ("WifiMac Tx", AnimationInterface::DOUBLE_COUNTER); - m_wifiMacTxDropCounterId = AddNodeCounter ("WifiMac TxDrop", AnimationInterface::DOUBLE_COUNTER); - m_wifiMacRxCounterId = AddNodeCounter ("WifiMac Rx", AnimationInterface::DOUBLE_COUNTER); - m_wifiMacRxDropCounterId = AddNodeCounter ("WifiMac RxDrop", AnimationInterface::DOUBLE_COUNTER); - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - m_nodeWifiMacTx[n->GetId ()] = 0; - m_nodeWifiMacTxDrop[n->GetId ()] = 0; - m_nodeWifiMacRx[n->GetId ()] = 0; - m_nodeWifiMacRxDrop[n->GetId ()] = 0; - UpdateNodeCounter (m_wifiMacTxCounterId, n->GetId (), 0); - UpdateNodeCounter (m_wifiMacTxDropCounterId, n->GetId (), 0); - UpdateNodeCounter (m_wifiMacRxCounterId, n->GetId (), 0); - UpdateNodeCounter (m_wifiMacRxDropCounterId, n->GetId (), 0); - } - Simulator::Schedule (startTime, &AnimationInterface::TrackWifiMacCounters, this); -} - -void -AnimationInterface::EnableQueueCounters (Time startTime, Time stopTime, Time pollInterval) -{ - m_queueCountersStopTime = stopTime; - m_queueCountersPollInterval = pollInterval; - m_queueEnqueueCounterId = AddNodeCounter ("Enqueue", AnimationInterface::DOUBLE_COUNTER); - m_queueDequeueCounterId = AddNodeCounter ("Dequeue", AnimationInterface::DOUBLE_COUNTER); - m_queueDropCounterId = AddNodeCounter ("Queue Drop", AnimationInterface::DOUBLE_COUNTER); - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - m_nodeQueueEnqueue[n->GetId ()] = 0; - m_nodeQueueDequeue[n->GetId ()] = 0; - m_nodeQueueDrop[n->GetId ()] = 0; - UpdateNodeCounter (m_queueEnqueueCounterId, n->GetId (), 0); - UpdateNodeCounter (m_queueDequeueCounterId, n->GetId (), 0); - UpdateNodeCounter (m_queueDropCounterId, n->GetId (), 0); - } - Simulator::Schedule (startTime, &AnimationInterface::TrackQueueCounters, this); -} - -void -AnimationInterface::EnableIpv4L3ProtocolCounters (Time startTime, Time stopTime, Time pollInterval) -{ - m_ipv4L3ProtocolCountersStopTime = stopTime; - m_ipv4L3ProtocolCountersPollInterval = pollInterval; - m_ipv4L3ProtocolTxCounterId = AddNodeCounter ("Ipv4 Tx", AnimationInterface::DOUBLE_COUNTER); - m_ipv4L3ProtocolRxCounterId = AddNodeCounter ("Ipv4 Rx", AnimationInterface::DOUBLE_COUNTER); - m_ipv4L3ProtocolDropCounterId = AddNodeCounter ("Ipv4 Drop", AnimationInterface::DOUBLE_COUNTER); - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - m_nodeIpv4Tx[n->GetId ()] = 0; - m_nodeIpv4Rx[n->GetId ()] = 0; - m_nodeIpv4Drop[n->GetId ()] = 0; - UpdateNodeCounter (m_ipv4L3ProtocolTxCounterId, n->GetId (), 0); - UpdateNodeCounter (m_ipv4L3ProtocolRxCounterId, n->GetId (), 0); - UpdateNodeCounter (m_ipv4L3ProtocolDropCounterId, n->GetId (), 0); - } - Simulator::Schedule (startTime, &AnimationInterface::TrackIpv4L3ProtocolCounters, this); -} - -AnimationInterface & -AnimationInterface::EnableIpv4RouteTracking (std::string fileName, Time startTime, Time stopTime, Time pollInterval) -{ - SetOutputFile (fileName, true); - m_routingStopTime = stopTime; - m_routingPollInterval = pollInterval; - WriteXmlAnim (true); - Simulator::Schedule (startTime, &AnimationInterface::TrackIpv4Route, this); - return *this; -} - -AnimationInterface & -AnimationInterface::EnableIpv4RouteTracking (std::string fileName, Time startTime, Time stopTime, NodeContainer nc, Time pollInterval) -{ - m_routingNc = nc; - return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval); -} - -AnimationInterface & -AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address) -{ - Ipv4RouteTrackElement element = { ipv4Address, fromNodeId }; - m_ipv4RouteTrackElements.push_back (element); - return *this; -} - -void -AnimationInterface::SetStartTime (Time t) -{ - m_startTime = t; -} - -void -AnimationInterface::SetStopTime (Time t) -{ - m_stopTime = t; -} - -void -AnimationInterface::SetMaxPktsPerTraceFile (uint64_t maxPacketsPerFile) -{ - m_maxPktsPerFile = maxPacketsPerFile; -} - -uint32_t -AnimationInterface::AddNodeCounter (std::string counterName, CounterType counterType) -{ - m_nodeCounters.push_back (counterName); - uint32_t counterId = m_nodeCounters.size () - 1; // counter ID is zero-indexed - WriteXmlAddNodeCounter (counterId, counterName, counterType); - return counterId; -} - -uint32_t -AnimationInterface::AddResource (std::string resourcePath) -{ - m_resources.push_back (resourcePath); - uint32_t resourceId = m_resources.size () - 1; // resource ID is zero-indexed - WriteXmlAddResource (resourceId, resourcePath); - return resourceId; -} - -void -AnimationInterface::EnablePacketMetadata (bool enable) -{ - m_enablePacketMetadata = enable; - if (enable) - { - Packet::EnablePrinting (); - } -} - -bool -AnimationInterface::IsInitialized () -{ - return initialized; -} - -bool -AnimationInterface::IsStarted () -{ - return m_started; -} - -void -AnimationInterface::SetAnimWriteCallback (AnimWriteCallback cb) -{ - m_writeCallback = cb; -} - -void -AnimationInterface::ResetAnimWriteCallback () -{ - m_writeCallback = 0; -} - -void -AnimationInterface::SetMobilityPollInterval (Time t) -{ - m_mobilityPollInterval = t; -} - - -void -AnimationInterface::SetConstantPosition (Ptr n, double x, double y, double z) -{ - NS_ASSERT (n); - Ptr loc = n->GetObject (); - if (loc == 0) - { - loc = CreateObject (); - n->AggregateObject (loc); - } - Vector hubVec (x, y, z); - loc->SetPosition (hubVec); - NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")"); - -} - -void -AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId) -{ - NS_LOG_INFO ("Setting node image for Node Id:" << nodeId); - if (resourceId > (m_resources.size ()-1)) - { - NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?"); - } - WriteXmlUpdateNodeImage (nodeId, resourceId); -} - -void -AnimationInterface::UpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counter) -{ - if (nodeCounterId > (m_nodeCounters.size () - 1)) - { - NS_FATAL_ERROR ("NodeCounter Id:" << nodeCounterId << " not found. Did you use AddNodeCounter?"); - } - WriteXmlUpdateNodeCounter (nodeCounterId, nodeId, counter); -} - -void -AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity) -{ - if ((opacity < 0) || (opacity > 1)) - { - NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0"); - } - WriteXmlUpdateBackground (fileName, x, y, scaleX, scaleY, opacity); -} - -void -AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height) -{ - AnimationInterface::NodeSize s = { width, height }; - m_nodeSizes[nodeId] = s; - WriteXmlUpdateNodeSize (nodeId, s.width, s.height); -} - -void -AnimationInterface::UpdateNodeColor (Ptr n, uint8_t r, uint8_t g, uint8_t b) -{ - UpdateNodeColor (n->GetId (), r, g, b); -} - -void -AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b) -{ - NS_ASSERT (NodeList::GetNode (nodeId)); - NS_LOG_INFO ("Setting node color for Node Id:" << nodeId); - Rgb rgb = {r, g, b}; - m_nodeColors[nodeId] = rgb; - WriteXmlUpdateNodeColor (nodeId, r, g, b); -} - -void -AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode, - std::string linkDescription) -{ - WriteXmlUpdateLink (fromNode, toNode, linkDescription); -} - -void -AnimationInterface::UpdateLinkDescription (Ptr fromNode, Ptr toNode, - std::string linkDescription) -{ - NS_ASSERT (fromNode); - NS_ASSERT (toNode); - WriteXmlUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription); -} - -void -AnimationInterface::UpdateNodeDescription (Ptr n, std::string descr) -{ - UpdateNodeDescription (n->GetId (), descr); -} - -void -AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr) -{ - NS_ASSERT (NodeList::GetNode (nodeId)); - m_nodeDescriptions[nodeId] = descr; - WriteXmlUpdateNodeDescription (nodeId); -} - -// Private methods - - -double -AnimationInterface::GetNodeEnergyFraction (Ptr node) const -{ - const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ()); - NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ()); - return fractionIter->second; -} - -void -AnimationInterface::MobilityCourseChangeTrace (Ptr mobility) -{ - CHECK_STARTED_INTIMEWINDOW; - Ptr n = mobility->GetObject (); - NS_ASSERT (n); - Vector v ; - if (!mobility) - { - v = GetPosition (n); - } - else - { - v = mobility->GetPosition (); - } - UpdatePosition (n, v); - WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y); -} - -bool -AnimationInterface::NodeHasMoved (Ptr n, Vector newLocation) -{ - Vector oldLocation = GetPosition (n); - bool moved = true; - if ((ceil (oldLocation.x) == ceil (newLocation.x)) && - (ceil (oldLocation.y) == ceil (newLocation.y))) - { - moved = false; - } - else - { - moved = true; - } - return moved; -} - -void -AnimationInterface::MobilityAutoCheck () -{ - CHECK_STARTED_INTIMEWINDOW; - std::vector > MovedNodes = GetMovedNodes (); - for (uint32_t i = 0; i < MovedNodes.size (); i++) - { - Ptr n = MovedNodes [i]; - NS_ASSERT (n); - Vector v = GetPosition (n); - WriteXmlUpdateNodePosition (n->GetId () , v.x, v.y); - } - if (!Simulator::IsFinished ()) - { - PurgePendingPackets (AnimationInterface::WIFI); - PurgePendingPackets (AnimationInterface::WIMAX); - PurgePendingPackets (AnimationInterface::LTE); - PurgePendingPackets (AnimationInterface::CSMA); - PurgePendingPackets (AnimationInterface::LRWPAN); - PurgePendingPackets (AnimationInterface::WAVE); - Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this); - } -} - -std::vector > -AnimationInterface::GetMovedNodes () -{ - std::vector < Ptr > movedNodes; - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - NS_ASSERT (n); - Ptr mobility = n->GetObject (); - Vector newLocation; - if (!mobility) - { - newLocation = GetPosition (n); - } - else - { - newLocation = mobility->GetPosition (); - } - if (!NodeHasMoved (n, newLocation)) - { - continue; //Location has not changed - } - else - { - UpdatePosition (n, newLocation); - movedNodes.push_back (n); - } - } - return movedNodes; -} - -int -AnimationInterface::WriteN (const std::string& st, FILE * f) -{ - if (!f) - { - return 0; - } - if (m_writeCallback) - { - m_writeCallback (st.c_str ()); - } - return WriteN (st.c_str (), st.length (), f); -} - -int -AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f) -{ - if (!f) - { - return 0; - } - // Write count bytes to h from data - uint32_t nLeft = count; - const char* p = data; - uint32_t written = 0; - while (nLeft) - { - int n = std::fwrite (p, 1, nLeft, f); - if (n <= 0) - { - return written; - } - written += n; - nLeft -= n; - p += n; - } - return written; -} - -void -AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements) -{ - NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ()); - WriteXmlRp (nodeId, destination, rpElements); - /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin (); - i != rpElements.end (); - ++i) - { - Ipv4RoutePathElement rpElement = *i; - NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ()); - WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF); - - } - */ -} - -void -AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType) -{ - WriteXmlNonP2pLinkProperties (id, ipv4Address, channelType); -} - -const std::vector -AnimationInterface::GetElementsFromContext (const std::string& context) const -{ - std::vector elements; - size_t pos1=0, pos2; - while (pos1 != context.npos) - { - pos1 = context.find ("/",pos1); - pos2 = context.find ("/",pos1+1); - elements.push_back (context.substr (pos1+1,pos2-(pos1+1))); - pos1 = pos2; - pos2 = context.npos; - } - return elements; -} - -Ptr -AnimationInterface::GetNodeFromContext (const std::string& context) const -{ - // Use "NodeList/*/ as reference - // where element [1] is the Node Id - - std::vector elements = GetElementsFromContext (context); - Ptr n = NodeList::GetNode (atoi (elements.at (1).c_str ())); - NS_ASSERT (n); - - return n; -} - -Ptr -AnimationInterface::GetNetDeviceFromContext (std::string context) -{ - // Use "NodeList/*/DeviceList/*/ as reference - // where element [1] is the Node Id - // element [2] is the NetDevice Id - - std::vector elements = GetElementsFromContext (context); - Ptr n = GetNodeFromContext (context); - - return n->GetDevice (atoi (elements.at (3).c_str ())); -} - -uint64_t -AnimationInterface::GetAnimUidFromPacket (Ptr p) -{ - AnimByteTag tag; - TypeId tid = tag.GetInstanceTypeId (); - ByteTagIterator i = p->GetByteTagIterator (); - bool found = false; - while (i.HasNext ()) - { - ByteTagIterator::Item item = i.Next (); - if (tid == item.GetTypeId ()) - { - item.GetTag (tag); - found = true; - } - } - if (found) - { - return tag.Get (); - } - else - { - return 0; - } -} - -void -AnimationInterface::AddByteTag (uint64_t animUid, Ptr p) -{ - AnimByteTag tag; - tag.Set (animUid); - p->AddByteTag (tag); -} - -void -AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy) -{ - CHECK_STARTED_INTIMEWINDOW; - const Ptr node = GetNodeFromContext (context); - const uint32_t nodeId = node->GetId (); - - NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy); - - const Ptr energySource = node->GetObject (); - - NS_ASSERT (energySource); - // Don't call GetEnergyFraction () because of recursion - const double energyFraction = currentEnergy / energySource->GetInitialEnergy (); - - NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction); - - m_nodeEnergyFraction[nodeId] = energyFraction; - UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction); -} - -void -AnimationInterface::WifiPhyTxDropTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeWifiPhyTxDrop[node->GetId ()]; -} - -void -AnimationInterface::WifiPhyRxDropTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeWifiPhyRxDrop[node->GetId ()]; -} - -void -AnimationInterface::WifiMacTxTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeWifiMacTx[node->GetId ()]; -} - -void -AnimationInterface::WifiMacTxDropTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeWifiMacTxDrop[node->GetId ()]; -} - -void -AnimationInterface::WifiMacRxTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeWifiMacRx[node->GetId ()]; -} - -void -AnimationInterface::WifiMacRxDropTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeWifiMacRxDrop[node->GetId ()]; -} - -void -AnimationInterface::LrWpanMacTxTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeLrWpanMacTx[node->GetId ()]; -} - -void -AnimationInterface::LrWpanMacTxDropTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeLrWpanMacTxDrop[node->GetId ()]; -} - -void -AnimationInterface::LrWpanMacRxTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeLrWpanMacRx[node->GetId ()]; -} - -void -AnimationInterface::LrWpanMacRxDropTrace (std::string context, Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeLrWpanMacRxDrop[node->GetId ()]; -} - -void -AnimationInterface::Ipv4TxTrace (std::string context, Ptr p, Ptr ipv4, uint32_t interfaceIndex) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeIpv4Tx[node->GetId ()]; -} - -void -AnimationInterface::Ipv4RxTrace (std::string context, Ptr p, Ptr ipv4, uint32_t interfaceIndex) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeIpv4Rx[node->GetId ()]; -} - -void -AnimationInterface::Ipv4DropTrace (std::string context, - const Ipv4Header & ipv4Header, - Ptr p, - Ipv4L3Protocol::DropReason dropReason, - Ptr ipv4, - uint32_t) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeIpv4Drop[node->GetId ()]; -} - -void -AnimationInterface::EnqueueTrace (std::string context, - Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeQueueEnqueue[node->GetId ()]; -} - -void -AnimationInterface::DequeueTrace (std::string context, - Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeQueueDequeue[node->GetId ()]; -} - -void -AnimationInterface::QueueDropTrace (std::string context, - Ptr p) -{ - const Ptr node = GetNodeFromContext (context); - ++m_nodeQueueDrop[node->GetId ()]; -} - -void -AnimationInterface::DevTxTrace (std::string context, - Ptr p, - Ptr tx, - Ptr rx, - Time txTime, - Time rxTime) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - NS_ASSERT (tx); - NS_ASSERT (rx); - Time now = Simulator::Now (); - double fbTx = now.GetSeconds (); - double lbTx = (now + txTime).GetSeconds (); - double fbRx = (now + rxTime - txTime).GetSeconds (); - double lbRx = (now + rxTime).GetSeconds (); - CheckMaxPktsPerTraceFile (); - WriteXmlP ("p", - tx->GetNode ()->GetId (), - fbTx, - lbTx, - rx->GetNode ()->GetId (), - fbRx, - lbRx, - m_enablePacketMetadata? GetPacketMetadata (p):""); -} - -void -AnimationInterface::GenericWirelessTxTrace (std::string context, Ptr p, ProtocolType protocolType) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - - ++gAnimUid; - NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessTxTrace for packet:" << gAnimUid); - AddByteTag (gAnimUid, p); - AnimPacketInfo pktInfo (ndev, Simulator::Now ()); - AddPendingPacket (protocolType, gAnimUid, pktInfo); - - Ptr netDevice = DynamicCast (ndev); - if (netDevice) - { - Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress (); - std::ostringstream oss; - oss << nodeAddr; - Ptr n = netDevice->GetNode (); - NS_ASSERT (n); - m_macToNodeIdMap[oss.str ()] = n->GetId (); - NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <at (gAnimUid), gAnimUid); -} - -void -AnimationInterface::GenericWirelessRxTrace (std::string context, Ptr p, ProtocolType protocolType) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - uint64_t animUid = GetAnimUidFromPacket (p); - NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " for packet:" << animUid); - if (!IsPacketPending (animUid, protocolType)) - { - NS_LOG_WARN (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessRxTrace: unknown Uid"); - return; - } - AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); - pendingPackets->at (animUid).ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); - OutputWirelessPacketRxInfo (p, pendingPackets->at (animUid), animUid); -} - -void -AnimationInterface::UanPhyGenTxTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessTxTrace (context, p, AnimationInterface::UAN); -} - -void -AnimationInterface::UanPhyGenRxTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessRxTrace (context, p, AnimationInterface::UAN); -} - -void -AnimationInterface::WifiPhyTxBeginTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessTxTrace (context, p, AnimationInterface::WIFI); -} - -void -AnimationInterface::WifiPhyRxBeginTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - uint64_t animUid = GetAnimUidFromPacket (p); - NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << animUid); - if (!IsPacketPending (animUid, AnimationInterface::WIFI)) - { - NS_ASSERT (0); - NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid"); - std::ostringstream oss; - WifiMacHeader hdr; - if (!p->PeekHeader (hdr)) - { - NS_LOG_WARN ("WifiMacHeader not present"); - return; - } - oss << hdr.GetAddr2 (); - if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ()) - { - NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping"); - return; - } - Ptr txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]); - UpdatePosition (txNode); - AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]); - AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo); - NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet"); - } - /// \todo NS_ASSERT (WifiPacketIsPending (animUid) == true); - m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); - OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid); -} - -void -AnimationInterface::LrWpanPhyTxBeginTrace (std::string context, - Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - Ptr netDevice = DynamicCast (ndev); - - Ptr n = ndev->GetNode (); - NS_ASSERT (n); - - UpdatePosition (n); - - LrWpanMacHeader hdr; - if (!p->PeekHeader (hdr)) - { - NS_LOG_WARN ("LrWpanMacHeader not present"); - return; - } - - std::ostringstream oss; - if (hdr.GetSrcAddrMode () == 2) - { - Mac16Address nodeAddr = netDevice->GetMac ()->GetShortAddress (); - oss << nodeAddr; - } - else if (hdr.GetSrcAddrMode () == 3) - { - Mac64Address nodeAddr = netDevice->GetMac ()->GetExtendedAddress (); - oss << nodeAddr; - } - else - { - NS_LOG_WARN ("LrWpanMacHeader without source address"); - return; - } - m_macToNodeIdMap[oss.str ()] = n->GetId (); - NS_LOG_INFO ("Added Mac" << oss.str () << " node:" < p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - Ptr n = ndev->GetNode (); - NS_ASSERT (n); - - AnimByteTag tag; - if (!p->FindFirstMatchingByteTag (tag)) - { - return; - } - - uint64_t animUid = GetAnimUidFromPacket (p); - NS_LOG_INFO ("LrWpan RxBeginTrace for packet:" << animUid); - if (!IsPacketPending (animUid, AnimationInterface::LRWPAN)) - { - NS_LOG_WARN ("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK."); - } - - UpdatePosition (n); - m_pendingLrWpanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); - OutputWirelessPacketRxInfo (p, m_pendingLrWpanPackets[animUid], animUid); -} - -void -AnimationInterface::WavePhyTxBeginTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessTxTrace (context, p, AnimationInterface::WAVE); -} - -void -AnimationInterface::WavePhyRxBeginTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - uint64_t animUid = GetAnimUidFromPacket (p); - NS_LOG_INFO ("Wave RxBeginTrace for packet:" << animUid); - if (!IsPacketPending (animUid, AnimationInterface::WAVE)) - { - NS_ASSERT (0); - NS_LOG_WARN ("WavePhyRxBeginTrace: unknown Uid"); - std::ostringstream oss; - WifiMacHeader hdr; - if (!p->PeekHeader (hdr)) - { - NS_LOG_WARN ("WaveMacHeader not present"); - return; - } - oss << hdr.GetAddr2 (); - if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ()) - { - NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping"); - return; - } - Ptr txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]); - UpdatePosition (txNode); - AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]); - AddPendingPacket (AnimationInterface::WAVE, animUid, pktInfo); - NS_LOG_WARN ("WavePhyRxBegin: unknown Uid, but we are adding a wave packet"); - } - /// \todo NS_ASSERT (WavePacketIsPending (animUid) == true); - m_pendingWavePackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); - OutputWirelessPacketRxInfo (p, m_pendingWavePackets[animUid], animUid); -} - - -void -AnimationInterface::WimaxTxTrace (std::string context, Ptr p, const Mac48Address & m) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessTxTrace (context, p, AnimationInterface::WIMAX); -} - - -void -AnimationInterface::WimaxRxTrace (std::string context, Ptr p, const Mac48Address & m) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessRxTrace (context, p, AnimationInterface::WIMAX); -} - -void -AnimationInterface::LteTxTrace (std::string context, Ptr p, const Mac48Address & m) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessTxTrace (context, p, AnimationInterface::LTE); -} - -void -AnimationInterface::LteRxTrace (std::string context, Ptr p, const Mac48Address & m) -{ - NS_LOG_FUNCTION (this); - return GenericWirelessRxTrace (context, p, AnimationInterface::LTE); -} - -void -AnimationInterface::LteSpectrumPhyTxStart (std::string context, Ptr pb) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - if (!pb) - { - NS_LOG_WARN ("pb == 0. Not yet supported"); - return; - } - context = "/" + context; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - - std::list > pbList = pb->GetPackets (); - for (std::list >::iterator i = pbList.begin (); - i != pbList.end (); - ++i) - { - Ptr p = *i; - ++gAnimUid; - NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid); - AnimPacketInfo pktInfo (ndev, Simulator::Now ()); - AddByteTag (gAnimUid, p); - AddPendingPacket (AnimationInterface::LTE, gAnimUid, pktInfo); - OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid); - } -} - -void -AnimationInterface::LteSpectrumPhyRxStart (std::string context, Ptr pb) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - if (!pb) - { - NS_LOG_WARN ("pb == 0. Not yet supported"); - return; - } - context = "/" + context; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - - std::list > pbList = pb->GetPackets (); - for (std::list >::iterator i = pbList.begin (); - i != pbList.end (); - ++i) - { - Ptr p = *i; - uint64_t animUid = GetAnimUidFromPacket (p); - NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid); - if (!IsPacketPending (animUid, AnimationInterface::LTE)) - { - NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid"); - return; - } - AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid]; - pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); - OutputWirelessPacketRxInfo (p, pktInfo, animUid); - } -} - -void -AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - ++gAnimUid; - NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid); - AddByteTag (gAnimUid, p); - UpdatePosition (ndev); - AnimPacketInfo pktInfo (ndev, Simulator::Now ()); - AddPendingPacket (AnimationInterface::CSMA, gAnimUid, pktInfo); - - -} - -void -AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - uint64_t animUid = GetAnimUidFromPacket (p); - NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid); - if (!IsPacketPending (animUid, AnimationInterface::CSMA)) - { - NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid"); - NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid"); - AnimPacketInfo pktInfo (ndev, Simulator::Now ()); - AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo); - NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway"); - } - /// \todo NS_ASSERT (IsPacketPending (AnimUid) == true); - AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid]; - pktInfo.m_lbTx = Simulator::Now ().GetSeconds (); -} - -void -AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - UpdatePosition (ndev); - uint64_t animUid = GetAnimUidFromPacket (p); - if (!IsPacketPending (animUid, AnimationInterface::CSMA)) - { - NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid"); - return; - } - /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); - AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid]; - pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); - NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid); - NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete"); - OutputCsmaPacket (p, pktInfo); -} - -void -AnimationInterface::CsmaMacRxTrace (std::string context, - Ptr p) -{ - NS_LOG_FUNCTION (this); - CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; - Ptr ndev = GetNetDeviceFromContext (context); - NS_ASSERT (ndev); - uint64_t animUid = GetAnimUidFromPacket (p); - if (!IsPacketPending (animUid, AnimationInterface::CSMA)) - { - NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid"); - return; - } - /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); - AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid]; - NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete"); - OutputCsmaPacket (p, pktInfo); -} - -void -AnimationInterface::OutputWirelessPacketTxInfo (Ptr p, AnimPacketInfo &pktInfo, uint64_t animUid) -{ - CheckMaxPktsPerTraceFile (); - uint32_t nodeId = 0; - if (pktInfo.m_txnd) - { - nodeId = pktInfo.m_txnd->GetNode ()->GetId (); - } - else - { - nodeId = pktInfo.m_txNodeId; - } - WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):""); -} - -void -AnimationInterface::OutputWirelessPacketRxInfo (Ptr p, AnimPacketInfo & pktInfo, uint64_t animUid) -{ - CheckMaxPktsPerTraceFile (); - uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId (); - WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx); -} - -void -AnimationInterface::OutputCsmaPacket (Ptr p, AnimPacketInfo &pktInfo) -{ - CheckMaxPktsPerTraceFile (); - NS_ASSERT (pktInfo.m_txnd); - uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId (); - uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId (); - - WriteXmlP ("p", - nodeId, - pktInfo.m_fbTx, - pktInfo.m_lbTx, - rxId, - pktInfo.m_fbRx, - pktInfo.m_lbRx, - m_enablePacketMetadata? GetPacketMetadata (p):""); -} - -void -AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo) -{ - AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); - NS_ASSERT (pendingPackets); - pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo)); -} - -bool -AnimationInterface::IsPacketPending (uint64_t animUid, AnimationInterface::ProtocolType protocolType) -{ - AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); - NS_ASSERT (pendingPackets); - return (pendingPackets->find (animUid) != pendingPackets->end ()); -} - -void -AnimationInterface::PurgePendingPackets (AnimationInterface::ProtocolType protocolType) -{ - AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); - NS_ASSERT (pendingPackets); - if (pendingPackets->empty ()) - { - return; - } - std::vector purgeList; - for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin (); - i != pendingPackets->end (); - ++i) - { - - AnimPacketInfo pktInfo = i->second; - double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx); - if (delta > PURGE_INTERVAL) - { - purgeList.push_back (i->first); - } - } - for (std::vector ::iterator i = purgeList.begin (); - i != purgeList.end (); - ++i) - { - pendingPackets->erase (*i); - } -} - -AnimationInterface::AnimUidPacketInfoMap * -AnimationInterface::ProtocolTypeToPendingPackets (AnimationInterface::ProtocolType protocolType) -{ - AnimUidPacketInfoMap * pendingPackets = 0; - switch (protocolType) - { - case AnimationInterface::WIFI: - { - pendingPackets = &m_pendingWifiPackets; - break; - } - case AnimationInterface::UAN: - { - pendingPackets = &m_pendingUanPackets; - break; - } - case AnimationInterface::CSMA: - { - pendingPackets = &m_pendingCsmaPackets; - break; - } - case AnimationInterface::WIMAX: - { - pendingPackets = &m_pendingWimaxPackets; - break; - } - case AnimationInterface::LTE: - { - pendingPackets = &m_pendingLtePackets; - break; - } - case AnimationInterface::LRWPAN: - { - pendingPackets = &m_pendingLrWpanPackets; - break; - } - case AnimationInterface::WAVE: - { - pendingPackets = &m_pendingWavePackets; - break; - } - } - return pendingPackets; - -} - -std::string -AnimationInterface::ProtocolTypeToString (AnimationInterface::ProtocolType protocolType) -{ - std::string result = "Unknown"; - switch (protocolType) - { - case AnimationInterface::WIFI: - { - result = "WIFI"; - break; - } - case AnimationInterface::UAN: - { - result = "UAN"; - break; - } - case AnimationInterface::CSMA: - { - result = "CSMA"; - break; - } - case AnimationInterface::WIMAX: - { - result = "WIMAX"; - break; - } - case AnimationInterface::LTE: - { - result = "LTE"; - break; - } - case AnimationInterface::LRWPAN: - { - result = "LRWPAN"; - break; - } - case AnimationInterface::WAVE: - { - result = "WAVE"; - break; - } - } - return result; -} - -// Counters - -std::string -AnimationInterface::CounterTypeToString (CounterType counterType) -{ - std::string typeString = "unknown"; - switch (counterType) - { - case UINT32_COUNTER: - { - typeString = "UINT32"; - break; - } - case DOUBLE_COUNTER: - { - typeString = "DOUBLE"; - break; - } - } - return typeString; -} - -// General - -std::string -AnimationInterface::GetPacketMetadata (Ptr p) -{ - std::ostringstream oss; - p->Print (oss); - return oss.str (); -} - -uint64_t -AnimationInterface::GetTracePktCount () -{ - return m_currentPktCount; -} - -void -AnimationInterface::StopAnimation (bool onlyAnimation) -{ - m_started = false; - NS_LOG_INFO ("Stopping Animation"); - ResetAnimWriteCallback (); - if (m_f) - { - // Terminate the anim element - WriteXmlClose ("anim"); - std::fclose (m_f); - m_f = 0; - } - if (onlyAnimation) - { - return; - } - if (m_routingF) - { - WriteXmlClose ("anim", true); - std::fclose (m_routingF); - m_routingF = 0; - } -} - -void -AnimationInterface::StartAnimation (bool restart) -{ - m_currentPktCount = 0; - m_started = true; - SetOutputFile (m_outputFileName); - WriteXmlAnim (); - WriteNodes (); - WriteNodeColors (); - WriteLinkProperties (); - WriteIpv4Addresses (); - WriteIpv6Addresses (); - WriteNodeSizes (); - WriteNodeEnergies (); - if (!restart) - { - Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this); - ConnectCallbacks (); - } -} - -void -AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId) -{ - m_ipv4ToNodeIdMap[ipv4Address] = nodeId; - m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address)); -} - -void -AnimationInterface::AddToIpv4AddressNodeIdTable (std::vector ipv4Addresses, uint32_t nodeId) -{ - for (std::vector::const_iterator i = ipv4Addresses.begin (); - i != ipv4Addresses.end (); - ++i) - { - AddToIpv4AddressNodeIdTable (*i, nodeId); - } -} - -void -AnimationInterface::AddToIpv6AddressNodeIdTable(std::string ipv6Address, uint32_t nodeId) -{ - m_ipv6ToNodeIdMap[ipv6Address] = nodeId; - m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address)); -} - -void -AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector ipv6Addresses, uint32_t nodeId) -{ - for (std::vector::const_iterator i = ipv6Addresses.begin(); - i != ipv6Addresses.end(); - ++i) - { - AddToIpv6AddressNodeIdTable(*i, nodeId); - } -} - -// Callbacks -void -AnimationInterface::ConnectLteEnb (Ptr n, Ptr nd, uint32_t devIndex) -{ - - Ptr lteEnbPhy = nd->GetPhy (); - Ptr dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy (); - Ptr ulPhy = lteEnbPhy->GetUplinkSpectrumPhy (); - std::ostringstream oss; - //NodeList/*/DeviceList/*/ - oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/"; - if (dlPhy) - { - dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); - dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); - } - if (ulPhy) - { - ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); - ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); - } -} - - - -void -AnimationInterface::ConnectLteUe (Ptr n, Ptr nd, uint32_t devIndex) -{ - - Ptr lteUePhy = nd->GetPhy (); - Ptr dlPhy = lteUePhy->GetDownlinkSpectrumPhy (); - Ptr ulPhy = lteUePhy->GetUplinkSpectrumPhy (); - std::ostringstream oss; - //NodeList/*/DeviceList/*/ - oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/"; - if (dlPhy) - { - dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); - dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); - } - if (ulPhy) - { - ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); - ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); - } -} - -void -AnimationInterface::ConnectLte () -{ - - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - NS_ASSERT (n); - uint32_t nDevices = n->GetNDevices (); - for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex) - { - Ptr nd = n->GetDevice (devIndex); - if (!nd) - continue; - Ptr lteUeNetDevice = DynamicCast (nd); - if (lteUeNetDevice) - { - ConnectLteUe (n, lteUeNetDevice, devIndex); - continue; - } - Ptr lteEnbNetDevice = DynamicCast (nd); - if (lteEnbNetDevice) - ConnectLteEnb (n, lteEnbNetDevice, devIndex); - } - - } -} - -void -AnimationInterface::ConnectCallbacks () -{ - // Connect the callbacks - Config::Connect ("/ChannelList/*/TxRxPointToPoint", - MakeCallback (&AnimationInterface::DevTxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin", - MakeCallback (&AnimationInterface::WifiPhyTxBeginTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin", - MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace, this)); - Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange", - MakeCallback (&AnimationInterface::MobilityCourseChangeTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx", - MakeCallback (&AnimationInterface::WimaxTxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx", - MakeCallback (&AnimationInterface::WimaxRxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx", - MakeCallback (&AnimationInterface::LteTxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx", - MakeCallback (&AnimationInterface::LteRxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin", - MakeCallback (&AnimationInterface::CsmaPhyTxBeginTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd", - MakeCallback (&AnimationInterface::CsmaPhyTxEndTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd", - MakeCallback (&AnimationInterface::CsmaPhyRxEndTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx", - MakeCallback (&AnimationInterface::CsmaMacRxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin", - MakeCallback (&AnimationInterface::UanPhyGenTxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin", - MakeCallback (&AnimationInterface::UanPhyGenRxTrace, this)); - Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy", - MakeCallback (&AnimationInterface::RemainingEnergyTrace, this)); - - ConnectLte (); - - Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx", - MakeCallback (&AnimationInterface::Ipv4TxTrace, this)); - Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx", - MakeCallback (&AnimationInterface::Ipv4RxTrace, this)); - Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop", - MakeCallback (&AnimationInterface::Ipv4DropTrace, this)); - - // Queue Enqueues - - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue", - MakeCallback (&AnimationInterface::EnqueueTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue", - MakeCallback (&AnimationInterface::EnqueueTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue", - MakeCallback (&AnimationInterface::EnqueueTrace, this)); - - // Queue Dequeues - - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue", - MakeCallback (&AnimationInterface::DequeueTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue", - MakeCallback (&AnimationInterface::DequeueTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue", - MakeCallback (&AnimationInterface::DequeueTrace, this)); - - // Queue Drops - - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop", - MakeCallback (&AnimationInterface::QueueDropTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop", - MakeCallback (&AnimationInterface::QueueDropTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop", - MakeCallback (&AnimationInterface::QueueDropTrace, this)); - - - // Wifi Mac - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx", - MakeCallback (&AnimationInterface::WifiMacTxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop", - MakeCallback (&AnimationInterface::WifiMacTxDropTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx", - MakeCallback (&AnimationInterface::WifiMacRxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop", - MakeCallback (&AnimationInterface::WifiMacRxDropTrace, this)); - - // Wifi Phy - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop", - MakeCallback (&AnimationInterface::WifiPhyTxDropTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop", - MakeCallback (&AnimationInterface::WifiPhyRxDropTrace, this)); - - // LrWpan - Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin", - MakeCallback (&AnimationInterface::LrWpanPhyTxBeginTrace, this)); - Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin", - MakeCallback (&AnimationInterface::LrWpanPhyRxBeginTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx", - MakeCallback (&AnimationInterface::LrWpanMacTxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop", - MakeCallback (&AnimationInterface::LrWpanMacTxDropTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx", - MakeCallback (&AnimationInterface::LrWpanMacRxTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop", - MakeCallback (&AnimationInterface::LrWpanMacRxDropTrace, this)); - - // Wave - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyTxBegin", - MakeCallback (&AnimationInterface::WavePhyTxBeginTrace, this)); - Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyRxBegin", - MakeCallback (&AnimationInterface::WavePhyRxBeginTrace, this)); -} - -Vector -AnimationInterface::UpdatePosition (Ptr n) -{ - Ptr loc = n->GetObject (); - if (loc) - { - m_nodeLocation[n->GetId ()] = loc->GetPosition (); - } - else - { - NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary"); - Ptr x = CreateObject (); - x->SetAttribute ("Min", DoubleValue (0)); - x->SetAttribute ("Max", DoubleValue (100)); - Ptr y = CreateObject (); - y->SetAttribute ("Min", DoubleValue (0)); - y->SetAttribute ("Max", DoubleValue (100)); - m_nodeLocation[n->GetId ()] = Vector (int (x->GetValue ()), int (y->GetValue ()), 0); - } - return m_nodeLocation[n->GetId ()]; -} - -Vector -AnimationInterface::UpdatePosition (Ptr n, Vector v) -{ - m_nodeLocation[n->GetId ()] = v; - return v; -} - -Vector -AnimationInterface::UpdatePosition (Ptr ndev) -{ - Ptr n = ndev->GetNode (); - NS_ASSERT (n); - return UpdatePosition (n); -} - -Vector -AnimationInterface::GetPosition (Ptr n) -{ - if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ()) - { - NS_FATAL_ERROR ("Node:" <GetId () << " not found in Location table"); - } - return m_nodeLocation[n->GetId ()]; -} - - -std::string -AnimationInterface::GetMacAddress (Ptr nd) -{ - Address nodeAddr = nd->GetAddress (); - std::ostringstream oss; - oss << nodeAddr; - return oss.str ().substr (6); // Skip the first 6 chars to get the Mac -} - -std::string -AnimationInterface::GetIpv4Address (Ptr nd) -{ - Ptr ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject (); - if (!ipv4) - { - NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found"); - return "0.0.0.0"; - } - int32_t ifIndex = ipv4->GetInterfaceForDevice (nd); - if (ifIndex == -1) - { - NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice"); - return "0.0.0.0"; - } - Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0); - std::ostringstream oss; - oss << addr.GetLocal (); - return oss.str (); -} - -std::string -AnimationInterface::GetIpv6Address(Ptr nd) -{ - Ptr ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject (); - if (!ipv6) - { - NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found"); - return "::"; - } - int32_t ifIndex = ipv6->GetInterfaceForDevice(nd); - if (ifIndex == -1) - { - NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice"); - return "::"; - } - bool nonLinkLocalFound = false; - uint32_t nAddresses = ipv6->GetNAddresses(ifIndex); - Ipv6InterfaceAddress addr; - for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex) - { - addr = ipv6->GetAddress(ifIndex, addressIndex); - if (!addr.GetAddress().IsLinkLocal()) - { - nonLinkLocalFound = true; - break; - } - } - if (!nonLinkLocalFound) - addr = ipv6->GetAddress(ifIndex, 0); - std::ostringstream oss; - oss << addr.GetAddress(); - return oss.str(); -} - - - -std::vector -AnimationInterface::GetIpv4Addresses (Ptr nd) -{ - std::vector ipv4Addresses; - Ptr ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject (); - if (!ipv4) - { - NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found"); - return ipv4Addresses; - } - int32_t ifIndex = ipv4->GetInterfaceForDevice (nd); - if (ifIndex == -1) - { - NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice"); - return ipv4Addresses; - } - for (uint32_t index = 0; index < ipv4->GetNAddresses (ifIndex); ++index) - { - Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, index); - std::ostringstream oss; - oss << addr.GetLocal (); - ipv4Addresses.push_back(oss.str ()); - } - return ipv4Addresses; -} - -std::vector -AnimationInterface::GetIpv6Addresses(Ptr nd) -{ - std::vector ipv6Addresses; - Ptr ipv6 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject (); - if (!ipv6) - { - NS_LOG_WARN("Node: " << nd->GetNode ()->GetId () << " No ipv6 object found"); - return ipv6Addresses; - } - int32_t ifIndex = ipv6->GetInterfaceForDevice (nd); - if (ifIndex == -1) - { - NS_LOG_WARN("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice"); - return ipv6Addresses; - } - for (uint32_t index = 0; index < ipv6->GetNAddresses (ifIndex); ++index) - { - Ipv6InterfaceAddress addr = ipv6->GetAddress (ifIndex, index); - std::ostringstream oss; - oss << addr.GetAddress (); - ipv6Addresses.push_back (oss.str ()); - } - return ipv6Addresses; -} - - -void -AnimationInterface::WriteIpv4Addresses () -{ - for (NodeIdIpv4Map::const_iterator i = m_nodeIdIpv4Map.begin (); - i != m_nodeIdIpv4Map.end(); - ++i) - { - std::vector ipv4Addresses; - std::pair iterPair = m_nodeIdIpv4Map.equal_range (i->first); - for (NodeIdIpv4Map::const_iterator it = iterPair.first; - it != iterPair.second; - ++it) - { - ipv4Addresses.push_back (it->second); - } - WriteXmlIpv4Addresses (i->first, ipv4Addresses); - } -} - -void -AnimationInterface::WriteIpv6Addresses() -{ - for (NodeIdIpv6Map::const_iterator i = m_nodeIdIpv6Map.begin (); - i != m_nodeIdIpv6Map.end (); - i = m_nodeIdIpv6Map.upper_bound (i->first)) - { - std::vector ipv6Addresses; - std::pair iterPair = m_nodeIdIpv6Map.equal_range (i->first); - for (NodeIdIpv6Map::const_iterator it = iterPair.first; - it != iterPair.second; - ++it) - { - ipv6Addresses.push_back (it->second); - } - WriteXmlIpv6Addresses (i->first, ipv6Addresses); - } -} - -void -AnimationInterface::WriteLinkProperties () -{ - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - UpdatePosition (n); - uint32_t n1Id = n->GetId (); - uint32_t nDev = n->GetNDevices (); // Number of devices - for (uint32_t i = 0; i < nDev; ++i) - { - Ptr dev = n->GetDevice (i); - NS_ASSERT (dev); - Ptr ch = dev->GetChannel (); - std::string channelType = "Unknown channel"; - if (ch) - { - channelType = ch->GetInstanceTypeId ().GetName (); - } - NS_LOG_DEBUG("Got ChannelType" << channelType); - - if (!ch || (channelType != std::string("ns3::PointToPointChannel"))) - { - NS_LOG_DEBUG ("No channel can't be a p2p device"); - /* - // Try to see if it is an LTE NetDevice, which does not return a channel - if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") || - (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")|| - (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice")) - { - WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType); - AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ()); - } - */ - std::vector ipv4Addresses = GetIpv4Addresses (dev); - AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId ()); - std::vector ipv6Addresses = GetIpv6Addresses (dev); - AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId ()); - if (!ipv4Addresses.empty ()) - { - NS_LOG_INFO ("Writing Ipv4 link"); - WriteNonP2pLinkProperties(n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType); - } - else if (!ipv6Addresses.empty ()) - { - NS_LOG_INFO ("Writing Ipv6 link"); - WriteNonP2pLinkProperties(n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType); - } - continue; - } - - else if (channelType == std::string ("ns3::PointToPointChannel")) - { // Since these are duplex links, we only need to dump - // if srcid < dstid - uint32_t nChDev = ch->GetNDevices (); - for (uint32_t j = 0; j < nChDev; ++j) - { - Ptr chDev = ch->GetDevice (j); - uint32_t n2Id = chDev->GetNode ()->GetId (); - if (n1Id < n2Id) - { - - std::vector ipv4Addresses = GetIpv4Addresses (dev); - AddToIpv4AddressNodeIdTable (ipv4Addresses, n1Id); - ipv4Addresses = GetIpv4Addresses (chDev); - AddToIpv4AddressNodeIdTable (ipv4Addresses, n2Id); - std::vector ipv6Addresses = GetIpv6Addresses (dev); - AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id); - ipv6Addresses = GetIpv6Addresses (chDev); - AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id); - - P2pLinkNodeIdPair p2pPair; - p2pPair.fromNode = n1Id; - p2pPair.toNode = n2Id; - if (!ipv4Addresses.empty ()) - { - LinkProperties lp = { GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), "" }; - m_linkProperties[p2pPair] = lp; - } - else if (!ipv6Addresses.empty ()) - { - LinkProperties lp = { GetIpv6Address (dev) + "~" + GetMacAddress (dev), GetIpv6Address (chDev) + "~" + GetMacAddress (chDev), "" }; - m_linkProperties[p2pPair] = lp; - } - WriteXmlLink (n1Id, 0, n2Id); - } - } - } - } - } - m_linkProperties.clear (); -} - -void -AnimationInterface::WriteNodes () -{ - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - NS_LOG_INFO ("Update Position for Node: " << n->GetId ()); - Vector v = UpdatePosition (n); - WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y); - } -} - -void -AnimationInterface::WriteNodeColors () -{ - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - Rgb rgb = {255, 0, 0}; - if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ()) - { - m_nodeColors[n->GetId ()] = rgb; - } - UpdateNodeColor (n, rgb.r, rgb.g, rgb.b); - } -} - -void -AnimationInterface::WriteNodeSizes () -{ - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - NS_LOG_INFO ("Update Size for Node: " << n->GetId ()); - AnimationInterface::NodeSize s = { 1, 1 }; - m_nodeSizes[n->GetId ()] = s; - UpdateNodeSize (n->GetId (), s.width, s.height); - } -} - -void -AnimationInterface::WriteNodeEnergies () -{ - m_remainingEnergyCounterId = AddNodeCounter ("RemainingEnergy", AnimationInterface::DOUBLE_COUNTER); - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - if (NodeList::GetNode (n->GetId ())->GetObject ()) - { - UpdateNodeCounter (m_remainingEnergyCounterId, n->GetId (), 1); - } - } -} - -bool -AnimationInterface::IsInTimeWindow () -{ - if ((Simulator::Now () >= m_startTime) && - (Simulator::Now () <= m_stopTime)) - return true; - else - return false; -} - -void -AnimationInterface::SetOutputFile (const std::string& fn, bool routing) -{ - if (!routing && m_f) - { - return; - } - if (routing && m_routingF) - { - NS_FATAL_ERROR ("SetRoutingOutputFile already used once"); - return; - } - - NS_LOG_INFO ("Creating new trace file:" << fn.c_str ()); - FILE * f = 0; - f = std::fopen (fn.c_str (), "w"); - if (!f) - { - NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ()); - return; // Can't open output file - } - if (routing) - { - m_routingF = f; - m_routingFileName = fn; - } - else - { - m_f = f; - m_outputFileName = fn; - } - return; -} - -void -AnimationInterface::CheckMaxPktsPerTraceFile () -{ - // Start a new trace file if the current packet count exceeded nax packets per file - ++m_currentPktCount; - if (m_currentPktCount <= m_maxPktsPerFile) - { - return; - } - NS_LOG_UNCOND ("Max Packets per trace file exceeded"); - StopAnimation (true); -} - -std::string -AnimationInterface::GetNetAnimVersion () -{ - return NETANIM_VERSION; -} - - -void -AnimationInterface::TrackQueueCounters () -{ - if (Simulator::Now () > m_queueCountersStopTime) - { - NS_LOG_INFO ("TrackQueueCounters Completed"); - return; - } - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - uint32_t nodeId = Ptr (*i)->GetId (); - UpdateNodeCounter (m_queueEnqueueCounterId, nodeId, m_nodeQueueEnqueue[nodeId]); - UpdateNodeCounter (m_queueDequeueCounterId, nodeId, m_nodeQueueDequeue[nodeId]); - UpdateNodeCounter (m_queueDropCounterId, nodeId, m_nodeQueueDrop[nodeId]); - } - Simulator::Schedule (m_queueCountersPollInterval, &AnimationInterface::TrackQueueCounters, this); -} - -void -AnimationInterface::TrackWifiMacCounters () -{ - if (Simulator::Now () > m_wifiMacCountersStopTime) - { - NS_LOG_INFO ("TrackWifiMacCounters Completed"); - return; - } - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - uint32_t nodeId = Ptr (*i)->GetId (); - UpdateNodeCounter (m_wifiMacTxCounterId, nodeId, m_nodeWifiMacTx[nodeId]); - UpdateNodeCounter (m_wifiMacTxDropCounterId, nodeId, m_nodeWifiMacTxDrop[nodeId]); - UpdateNodeCounter (m_wifiMacRxCounterId, nodeId, m_nodeWifiMacRx[nodeId]); - UpdateNodeCounter (m_wifiMacRxDropCounterId, nodeId, m_nodeWifiMacRxDrop[nodeId]); - } - Simulator::Schedule (m_wifiMacCountersPollInterval, &AnimationInterface::TrackWifiMacCounters, this); -} - -void -AnimationInterface::TrackWifiPhyCounters () -{ - if (Simulator::Now () > m_wifiPhyCountersStopTime) - { - NS_LOG_INFO ("TrackWifiPhyCounters Completed"); - return; - } - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - uint32_t nodeId = Ptr (*i)->GetId (); - UpdateNodeCounter (m_wifiPhyTxDropCounterId, nodeId, m_nodeWifiPhyTxDrop[nodeId]); - UpdateNodeCounter (m_wifiPhyRxDropCounterId, nodeId, m_nodeWifiPhyRxDrop[nodeId]); - } - Simulator::Schedule (m_wifiPhyCountersPollInterval, &AnimationInterface::TrackWifiPhyCounters, this); -} - -void -AnimationInterface::TrackIpv4L3ProtocolCounters () -{ - if (Simulator::Now () > m_ipv4L3ProtocolCountersStopTime) - { - NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed"); - return; - } - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - uint32_t nodeId = Ptr (*i)->GetId (); - UpdateNodeCounter (m_ipv4L3ProtocolTxCounterId, nodeId, m_nodeIpv4Tx[nodeId]); - UpdateNodeCounter (m_ipv4L3ProtocolRxCounterId, nodeId, m_nodeIpv4Rx[nodeId]); - UpdateNodeCounter (m_ipv4L3ProtocolDropCounterId, nodeId, m_nodeIpv4Drop[nodeId]); - } - Simulator::Schedule (m_ipv4L3ProtocolCountersPollInterval, &AnimationInterface::TrackIpv4L3ProtocolCounters, this); -} - - - - - -/***** Routing-related *****/ - -void -AnimationInterface::TrackIpv4RoutePaths () -{ - if (m_ipv4RouteTrackElements.empty ()) - { - return; - } - for (std::vector ::const_iterator i = m_ipv4RouteTrackElements.begin (); - i != m_ipv4RouteTrackElements.end (); - ++i) - { - Ipv4RouteTrackElement trackElement = *i; - Ptr fromNode = NodeList::GetNode (trackElement.fromNodeId); - if (!fromNode) - { - NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found"); - continue; - } - Ptr ipv4 = fromNode->GetObject (); - if (!ipv4) - { - NS_LOG_WARN ("ipv4 object not found"); - continue; - } - Ptr rp = ipv4->GetRoutingProtocol (); - if (!rp) - { - NS_LOG_WARN ("Routing protocol object not found"); - continue; - } - NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId); - Ptr pkt = Create (); - Ipv4Header header; - header.SetDestination (Ipv4Address (trackElement.destination.c_str ())); - Socket::SocketErrno sockerr; - Ptr rt = rp->RouteOutput (pkt, header, 0, sockerr); - Ipv4RoutePathElements rpElements; - if (!rt) - { - NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ()); - Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" }; - rpElements.push_back (elem); - WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements); - continue; - } - std::ostringstream oss; - oss << rt->GetGateway (); - NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ()); - if (rt->GetGateway () == "0.0.0.0") - { - Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" }; - rpElements.push_back (elem); - if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ()) - { - Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" }; - rpElements.push_back (elem2); - } - } - else if (rt->GetGateway () == "127.0.0.1") - { - Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" }; - rpElements.push_back (elem); - } - else - { - Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () }; - rpElements.push_back (elem); - } - RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements); - WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements); - } - -} - -void -AnimationInterface::TrackIpv4Route () -{ - if (Simulator::Now () > m_routingStopTime) - { - NS_LOG_INFO ("TrackIpv4Route completed"); - return; - } - if (m_routingNc.GetN ()) - { - for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i) - { - Ptr n = *i; - WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n)); - } - } - else - { - for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) - { - Ptr n = *i; - WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n)); - } - } - TrackIpv4RoutePaths (); - Simulator::Schedule (m_routingPollInterval, &AnimationInterface::TrackIpv4Route, this); -} - -std::string -AnimationInterface::GetIpv4RoutingTable (Ptr n) -{ - - NS_ASSERT (n); - Ptr ipv4 = n->GetObject (); - if (!ipv4) - { - NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object"); - return ""; - } - std::stringstream stream; - Ptr routingstream = Create (&stream); - ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream); - return stream.str (); - -} - -void -AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements) -{ - NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ()); - if ((from == "0.0.0.0") || (from == "127.0.0.1")) - { - NS_LOG_INFO ("Got " << from.c_str () << " End recursion"); - return; - } - Ptr fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]); - Ptr toNode = NodeList::GetNode (m_ipv4ToNodeIdMap[to]); - if (fromNode->GetId () == toNode->GetId ()) - { - Ipv4RoutePathElement elem = { fromNode->GetId (), "L" }; - rpElements.push_back (elem); - return; - } - if (!fromNode) - { - NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found"); - return; - } - if (!toNode) - { - NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found"); - return; - } - Ptr ipv4 = fromNode->GetObject (); - if (!ipv4) - { - NS_LOG_WARN ("ipv4 object not found"); - return; - } - Ptr rp = ipv4->GetRoutingProtocol (); - if (!rp) - { - NS_LOG_WARN ("Routing protocol object not found"); - return; - } - Ptr pkt = Create (); - Ipv4Header header; - header.SetDestination (Ipv4Address (to.c_str ())); - Socket::SocketErrno sockerr; - Ptr rt = rp->RouteOutput (pkt, header, 0, sockerr); - if (!rt) - { - return; - } - NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ()); - std::ostringstream oss; - oss << rt->GetGateway (); - if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST)) - { - NS_LOG_INFO ("Null gw"); - Ipv4RoutePathElement elem = { fromNode->GetId (), "C" }; - rpElements.push_back (elem); - if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ()) - { - Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" }; - rpElements.push_back (elem2); - } - return; - } - NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ()); - Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () }; - rpElements.push_back (elem); - RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements); - -} - - - -/***** WriteXml *****/ - -void -AnimationInterface::WriteXmlAnim (bool routing) -{ - AnimXmlElement element ("anim"); - element.AddAttribute ("ver", GetNetAnimVersion ()); - FILE * f = m_f; - if (!routing) - { - element.AddAttribute ("filetype", "animation"); - } - else - { - element.AddAttribute ("filetype", "routing"); - f = m_routingF; - } - WriteN (element.ToString (false) + ">\n", f); -} - -void -AnimationInterface::WriteXmlClose (std::string name, bool routing) -{ - std::string closeString = "\n"; - if (!routing) - { - WriteN (closeString, m_f); - } - else - { - WriteN (closeString, m_routingF); - } -} - -void -AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY) -{ - AnimXmlElement element ("node"); - element.AddAttribute ("id", id); - element.AddAttribute ("sysId", sysId); - element.AddAttribute ("locX", locX); - element.AddAttribute ("locY", locY); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription) -{ - AnimXmlElement element ("linkupdate"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("fromId", fromId); - element.AddAttribute ("toId", toId); - element.AddAttribute ("ld", linkDescription, true); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId) -{ - AnimXmlElement element ("link"); - element.AddAttribute ("fromId", fromId); - element.AddAttribute ("toId", toId); - - LinkProperties lprop ; - lprop.fromNodeDescription = ""; - lprop.toNodeDescription = ""; - lprop.linkDescription = ""; - - P2pLinkNodeIdPair p1 = { fromId, toId }; - P2pLinkNodeIdPair p2 = { toId, fromId }; - if (m_linkProperties.find (p1) != m_linkProperties.end ()) - { - lprop = m_linkProperties[p1]; - } - else if (m_linkProperties.find (p2) != m_linkProperties.end ()) - { - lprop = m_linkProperties[p2]; - } - - element.AddAttribute ("fd", lprop.fromNodeDescription, true); - element.AddAttribute ("td", lprop.toNodeDescription, true); - element.AddAttribute ("ld", lprop.linkDescription, true); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlIpv4Addresses (uint32_t nodeId, std::vector ipv4Addresses) -{ - AnimXmlElement element ("ip"); - element.AddAttribute ("n", nodeId); - for (std::vector::const_iterator i = ipv4Addresses.begin (); - i != ipv4Addresses.end (); - ++i) - { - AnimXmlElement valueElement ("address"); - valueElement.SetText (*i); - element.AppendChild(valueElement); - } - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlIpv6Addresses (uint32_t nodeId, std::vector ipv6Addresses) -{ - AnimXmlElement element ("ipv6"); - element.AddAttribute("n", nodeId); - for (std::vector::const_iterator i = ipv6Addresses.begin (); - i != ipv6Addresses.end (); - ++i) - { - AnimXmlElement valueElement ("address"); - valueElement.SetText (*i); - element.AppendChild (valueElement); - } - WriteN(element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo) -{ - AnimXmlElement element ("rt"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - element.AddAttribute ("info", routingInfo.c_str (), true); - WriteN (element.ToString (), m_routingF); -} - -void -AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements) -{ - std::string tagName = "rp"; - AnimXmlElement element (tagName, false); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - element.AddAttribute ("d", destination.c_str ()); - element.AddAttribute ("c", rpElements.size ()); - for (Ipv4RoutePathElements::const_iterator i = rpElements.begin (); - i != rpElements.end (); - ++i) - { - Ipv4RoutePathElement rpElement = *i; - AnimXmlElement rpeElement ("rpe"); - rpeElement.AddAttribute ("n", rpElement.nodeId); - rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ()); - element.AppendChild (rpeElement); - } - WriteN (element.ToString (), m_routingF); -} - - -void -AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo) -{ - AnimXmlElement element ("pr"); - element.AddAttribute ("uId", animUid); - element.AddAttribute ("fId", fId); - element.AddAttribute ("fbTx", fbTx); - if (!metaInfo.empty ()) - { - element.AddAttribute ("meta-info", metaInfo.c_str (), true); - } - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx) -{ - AnimXmlElement element (pktType); - element.AddAttribute ("uId", animUid); - element.AddAttribute ("tId", tId); - element.AddAttribute ("fbRx", fbRx); - element.AddAttribute ("lbRx", lbRx); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlP (std::string pktType, uint32_t fId, double fbTx, double lbTx, - uint32_t tId, double fbRx, double lbRx, std::string metaInfo) -{ - AnimXmlElement element (pktType); - element.AddAttribute ("fId", fId); - element.AddAttribute ("fbTx", fbTx); - element.AddAttribute ("lbTx", lbTx); - if (!metaInfo.empty ()) - { - element.AddAttribute ("meta-info", metaInfo.c_str (), true); - } - element.AddAttribute ("tId", tId); - element.AddAttribute ("fbRx", fbRx); - element.AddAttribute ("lbRx", lbRx); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType) -{ - AnimXmlElement element ("ncs"); - element.AddAttribute ("ncId", nodeCounterId); - element.AddAttribute ("n", counterName); - element.AddAttribute ("t", CounterTypeToString (counterType)); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath) -{ - AnimXmlElement element ("res"); - element.AddAttribute ("rid", resourceId); - element.AddAttribute ("p", resourcePath); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId) -{ - AnimXmlElement element ("nu"); - element.AddAttribute ("p", "i"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - element.AddAttribute ("rid", resourceId); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height) -{ - AnimXmlElement element ("nu"); - element.AddAttribute ("p", "s"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - element.AddAttribute ("w", width); - element.AddAttribute ("h", height); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y) -{ - AnimXmlElement element ("nu"); - element.AddAttribute ("p", "p"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - element.AddAttribute ("x", x); - element.AddAttribute ("y", y); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b) -{ - AnimXmlElement element ("nu"); - element.AddAttribute ("p", "c"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - element.AddAttribute ("r", (uint32_t) r); - element.AddAttribute ("g", (uint32_t) g); - element.AddAttribute ("b", (uint32_t) b); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId) -{ - AnimXmlElement element ("nu"); - element.AddAttribute ("p", "d"); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("id", nodeId); - if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ()) - { - element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true); - } - WriteN (element.ToString (), m_f); -} - - -void -AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue) -{ - AnimXmlElement element ("nc"); - element.AddAttribute ("c", nodeCounterId); - element.AddAttribute ("i", nodeId); - element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); - element.AddAttribute ("v", counterValue); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity) -{ - AnimXmlElement element ("bg"); - element.AddAttribute ("f", fileName); - element.AddAttribute ("x", x); - element.AddAttribute ("y", y); - element.AddAttribute ("sx", scaleX); - element.AddAttribute ("sy", scaleY); - element.AddAttribute ("o", opacity); - WriteN (element.ToString (), m_f); -} - -void -AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipAddress, std::string channelType) -{ - AnimXmlElement element ("nonp2plinkproperties"); - element.AddAttribute ("id", id); - element.AddAttribute ("ipAddress", ipAddress); - element.AddAttribute ("channelType", channelType); - WriteN (element.ToString (), m_f); -} - - - -/***** AnimXmlElement *****/ - -AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement) : - m_tagName(tagName), - m_text("") -{ -} - -template -void -AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape) -{ - std::ostringstream oss; - oss << std::setprecision(10); - oss << value; - std::string attributeString = attribute.c_str(); - if (xmlEscape) - { - attributeString += "=\""; - std::string valueStr = oss.str(); - for (std::string::iterator it = valueStr.begin(); it != valueStr.end(); ++it) - { - switch (*it) - { - case '&': - attributeString += "&"; - break; - case '\"': - attributeString += """; - break; - case '\'': - attributeString += "'"; - break; - case '<': - attributeString += "<"; - break; - case '>': - attributeString += ">"; - break; - default: - attributeString += *it; - break; - } - } - attributeString += "\" "; - } - else - { - attributeString += "=\"" + oss.str() + "\" "; - } - m_attributes.push_back(attributeString); -} - -void -AnimationInterface::AnimXmlElement::AppendChild(AnimXmlElement e) -{ - m_children.push_back(e.ToString()); -} - -void -AnimationInterface::AnimXmlElement::SetText(std::string text) -{ - m_text = text; -} - -std::string -AnimationInterface::AnimXmlElement::ToString(bool autoClose) -{ - std::string elementString = "<" + m_tagName + " "; - - - for (std::vector::const_iterator i = m_attributes.begin(); - i != m_attributes.end(); - ++i) - { - elementString += *i; - } - if (m_children.empty() && m_text.empty()) - { - if (autoClose) - { - elementString += "/>"; - } - } - else - { - elementString += ">"; - if (!m_text.empty()) - { - elementString += m_text; - } - if (!m_children.empty()) - { - elementString += "\n"; - for (std::vector::const_iterator i = m_children.begin(); - i != m_children.end(); - ++i) - { - elementString += *i + "\n"; - } - - } - if (autoClose) - { - elementString += ""; - } - } - - - return elementString + ((autoClose) ?"\n": ""); -} - - - - - -/***** AnimByteTag *****/ - -TypeId -AnimByteTag::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::AnimByteTag") - .SetParent () - .SetGroupName ("NetAnim") - .AddConstructor () - ; - return tid; -} - -TypeId -AnimByteTag::GetInstanceTypeId (void) const -{ - return GetTypeId (); -} - -uint32_t -AnimByteTag::GetSerializedSize (void) const -{ - return sizeof (uint64_t); -} - -void -AnimByteTag::Serialize (TagBuffer i) const -{ - i.WriteU64 (m_AnimUid); -} - -void -AnimByteTag::Deserialize (TagBuffer i) -{ - m_AnimUid = i.ReadU64 (); -} - -void -AnimByteTag::Print (std::ostream &os) const -{ - os << "AnimUid=" << m_AnimUid; -} - -void -AnimByteTag::Set (uint64_t AnimUid) -{ - m_AnimUid = AnimUid; -} - -uint64_t -AnimByteTag::Get (void) const -{ - return m_AnimUid; -} - -AnimationInterface::AnimPacketInfo::AnimPacketInfo () - : m_txnd (0), - m_txNodeId (0), - m_fbTx (0), - m_lbTx (0), - m_lbRx (0) -{ -} - -AnimationInterface::AnimPacketInfo::AnimPacketInfo (const AnimPacketInfo & pInfo) -{ - m_txnd = pInfo.m_txnd; - m_txNodeId = pInfo.m_txNodeId; - m_fbTx = pInfo.m_fbTx; - m_lbTx = pInfo.m_lbTx; - m_lbRx = pInfo.m_lbRx; -} - -AnimationInterface::AnimPacketInfo::AnimPacketInfo (Ptr txnd, - const Time fbTx, - uint32_t txNodeId) - : m_txnd (txnd), - m_txNodeId (0), - m_fbTx (fbTx.GetSeconds ()), - m_lbTx (0), - m_lbRx (0) -{ - if (!m_txnd) - m_txNodeId = txNodeId; -} - -void -AnimationInterface::AnimPacketInfo::ProcessRxBegin (Ptr nd, const double fbRx) -{ - Ptr n = nd->GetNode (); - m_fbRx = fbRx; - m_rxnd = nd; -} - -} // namespace ns3 + /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: George F. Riley + * Modified by: John Abraham + * Contributions: Eugene Kalishenko (Open Source and Linux Laboratory http://dev.osll.ru/) + * Tommaso Pecorella + * Pavel Vasilyev + */ + +// Interface between ns-3 and the GetNetAnimVersionwork AnimationInterface + + + +#include +#ifndef WIN32 +#include +#endif +#include +#include +#include +#include +#include +#include + +// ns3 includes +#include "ns3/animation-interface.h" +#include "ns3/channel.h" +#include "ns3/config.h" +#include "ns3/node.h" +#include "ns3/mobility-model.h" +#include "ns3/packet.h" +#include "ns3/simulator.h" +#include "ns3/wifi-mac-header.h" +#include "ns3/wimax-mac-header.h" +#include "ns3/wifi-net-device.h" +#include "ns3/wifi-mac.h" +#include "ns3/lr-wpan-mac-header.h" +#include "ns3/lr-wpan-net-device.h" +#include "ns3/constant-position-mobility-model.h" +#include "ns3/lte-ue-phy.h" +#include "ns3/lte-enb-phy.h" +#include "ns3/uan-net-device.h" +#include "ns3/uan-mac.h" +#include "ns3/double.h" +#include "ns3/ipv4.h" +#include "ns3/ipv6.h" +#include "ns3/ipv4-routing-protocol.h" +#include "ns3/energy-source-container.h" +#include "animation-interface.h" + +namespace ns3 { + +NS_LOG_COMPONENT_DEFINE ("AnimationInterface"); + +// Globals + +static bool initialized = false; //!< Initialization flag + +// Public methods +AnimationInterface::AnimationInterface () //Online Mode + : m_f (0), + m_routingF (0), + m_mobilityPollInterval (Seconds (0.25)), + m_outputFileName (""), + gAnimUid (0), + m_writeCallback (0), + m_started (false), + m_enablePacketMetadata (false), + m_startTime (Seconds (0)), + m_stopTime (Seconds (3600 * 1000)), + m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE), + m_originalFileName (""), + m_routingStopTime (Seconds (0)), + m_routingFileName (""), + m_routingPollInterval (Seconds (5)), + m_trackPackets (true), + m_onlineMode(true), + m_animxmlparser (0), + m_application (0), + m_netanim(0) +{ + initialized = true; + DefaultSimulatorImpl::setOnlineMode (true); + char name[] = "NetAnimOnline"; + char *argv = name; + int argc = 1; + m_application = new QApplication (argc, &argv); + m_application->setApplicationName ("NetAnimOnline"); + m_netanim = new netanim::NetAnim (true); + m_animxmlparser = netanim::AnimatorMode::getInstance ()->getAnimxmlparser (); + StartAnimation (); + netanim::AnimatorMode::getInstance ()->parseOnline (); + QApplication::exec (); +} + +AnimationInterface::AnimationInterface (const std::string fn) + : m_f (0), + m_routingF (0), + m_mobilityPollInterval (Seconds (0.25)), + m_outputFileName (fn), + gAnimUid (0), + m_writeCallback (0), + m_started (false), + m_enablePacketMetadata (false), + m_startTime (Seconds (0)), + m_stopTime (Seconds (3600 * 1000)), + m_maxPktsPerFile (MAX_PKTS_PER_TRACE_FILE), + m_originalFileName (fn), + m_routingStopTime (Seconds (0)), + m_routingFileName (""), + m_routingPollInterval (Seconds (5)), + m_trackPackets (true), + m_onlineMode(false), + m_animxmlparser (0), + m_application (0), + m_netanim(0) +{ + initialized = true; + StartAnimation (); +} + +AnimationInterface::~AnimationInterface () +{ + if(m_application) + { + delete m_application; + } + if(m_netanim) + { + delete m_netanim; + } + StopAnimation (); +} + +void +AnimationInterface::SkipPacketTracing () +{ + m_trackPackets = false; +} + +void +AnimationInterface::EnableWifiPhyCounters (Time startTime, Time stopTime, Time pollInterval) +{ + m_wifiPhyCountersStopTime = stopTime; + m_wifiPhyCountersPollInterval = pollInterval; + m_wifiPhyTxDropCounterId = AddNodeCounter ("WifiPhy TxDrop", AnimationInterface::DOUBLE_COUNTER); + m_wifiPhyRxDropCounterId = AddNodeCounter ("WifiPhy RxDrop", AnimationInterface::DOUBLE_COUNTER); + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + m_nodeWifiPhyTxDrop[n->GetId ()] = 0; + m_nodeWifiPhyRxDrop[n->GetId ()] = 0; + UpdateNodeCounter (m_wifiPhyTxDropCounterId, n->GetId (), 0); + UpdateNodeCounter (m_wifiPhyRxDropCounterId, n->GetId (), 0); + } + Simulator::Schedule (startTime, &AnimationInterface::TrackWifiPhyCounters, this); + +} + +void +AnimationInterface::EnableWifiMacCounters (Time startTime, Time stopTime, Time pollInterval) +{ + m_wifiMacCountersStopTime = stopTime; + m_wifiMacCountersPollInterval = pollInterval; + m_wifiMacTxCounterId = AddNodeCounter ("WifiMac Tx", AnimationInterface::DOUBLE_COUNTER); + m_wifiMacTxDropCounterId = AddNodeCounter ("WifiMac TxDrop", AnimationInterface::DOUBLE_COUNTER); + m_wifiMacRxCounterId = AddNodeCounter ("WifiMac Rx", AnimationInterface::DOUBLE_COUNTER); + m_wifiMacRxDropCounterId = AddNodeCounter ("WifiMac RxDrop", AnimationInterface::DOUBLE_COUNTER); + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + m_nodeWifiMacTx[n->GetId ()] = 0; + m_nodeWifiMacTxDrop[n->GetId ()] = 0; + m_nodeWifiMacRx[n->GetId ()] = 0; + m_nodeWifiMacRxDrop[n->GetId ()] = 0; + UpdateNodeCounter (m_wifiMacTxCounterId, n->GetId (), 0); + UpdateNodeCounter (m_wifiMacTxDropCounterId, n->GetId (), 0); + UpdateNodeCounter (m_wifiMacRxCounterId, n->GetId (), 0); + UpdateNodeCounter (m_wifiMacRxDropCounterId, n->GetId (), 0); + } + Simulator::Schedule (startTime, &AnimationInterface::TrackWifiMacCounters, this); +} + +void +AnimationInterface::EnableQueueCounters (Time startTime, Time stopTime, Time pollInterval) +{ + m_queueCountersStopTime = stopTime; + m_queueCountersPollInterval = pollInterval; + m_queueEnqueueCounterId = AddNodeCounter ("Enqueue", AnimationInterface::DOUBLE_COUNTER); + m_queueDequeueCounterId = AddNodeCounter ("Dequeue", AnimationInterface::DOUBLE_COUNTER); + m_queueDropCounterId = AddNodeCounter ("Queue Drop", AnimationInterface::DOUBLE_COUNTER); + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + m_nodeQueueEnqueue[n->GetId ()] = 0; + m_nodeQueueDequeue[n->GetId ()] = 0; + m_nodeQueueDrop[n->GetId ()] = 0; + UpdateNodeCounter (m_queueEnqueueCounterId, n->GetId (), 0); + UpdateNodeCounter (m_queueDequeueCounterId, n->GetId (), 0); + UpdateNodeCounter (m_queueDropCounterId, n->GetId (), 0); + } + Simulator::Schedule (startTime, &AnimationInterface::TrackQueueCounters, this); +} + +void +AnimationInterface::EnableIpv4L3ProtocolCounters (Time startTime, Time stopTime, Time pollInterval) +{ + m_ipv4L3ProtocolCountersStopTime = stopTime; + m_ipv4L3ProtocolCountersPollInterval = pollInterval; + m_ipv4L3ProtocolTxCounterId = AddNodeCounter ("Ipv4 Tx", AnimationInterface::DOUBLE_COUNTER); + m_ipv4L3ProtocolRxCounterId = AddNodeCounter ("Ipv4 Rx", AnimationInterface::DOUBLE_COUNTER); + m_ipv4L3ProtocolDropCounterId = AddNodeCounter ("Ipv4 Drop", AnimationInterface::DOUBLE_COUNTER); + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + m_nodeIpv4Tx[n->GetId ()] = 0; + m_nodeIpv4Rx[n->GetId ()] = 0; + m_nodeIpv4Drop[n->GetId ()] = 0; + UpdateNodeCounter (m_ipv4L3ProtocolTxCounterId, n->GetId (), 0); + UpdateNodeCounter (m_ipv4L3ProtocolRxCounterId, n->GetId (), 0); + UpdateNodeCounter (m_ipv4L3ProtocolDropCounterId, n->GetId (), 0); + } + Simulator::Schedule (startTime, &AnimationInterface::TrackIpv4L3ProtocolCounters, this); +} + +AnimationInterface & +AnimationInterface::EnableIpv4RouteTracking (std::string fileName, Time startTime, Time stopTime, Time pollInterval) +{ + SetOutputFile (fileName, true); + m_routingStopTime = stopTime; + m_routingPollInterval = pollInterval; + if(!m_onlineMode){ + WriteXmlAnim (true); + } + else + { + if(m_animxmlparser){ + m_animxmlparser->doParse(WriteAnim ()); + } + } + Simulator::Schedule (startTime, &AnimationInterface::TrackIpv4Route, this); + return *this; +} + +AnimationInterface & +AnimationInterface::EnableIpv4RouteTracking (std::string fileName, Time startTime, Time stopTime, NodeContainer nc, Time pollInterval) +{ + m_routingNc = nc; + return EnableIpv4RouteTracking (fileName, startTime, stopTime, pollInterval); +} + +AnimationInterface & +AnimationInterface::AddSourceDestination (uint32_t fromNodeId, std::string ipv4Address) +{ + Ipv4RouteTrackElement element = { ipv4Address, fromNodeId }; + m_ipv4RouteTrackElements.push_back (element); + return *this; +} + +void +AnimationInterface::SetStartTime (Time t) +{ + m_startTime = t; +} + +void +AnimationInterface::SetStopTime (Time t) +{ + m_stopTime = t; +} + +void +AnimationInterface::SetMaxPktsPerTraceFile (uint64_t maxPacketsPerFile) +{ + m_maxPktsPerFile = maxPacketsPerFile; +} + +uint32_t +AnimationInterface::AddNodeCounter (std::string counterName, CounterType counterType) +{ + m_nodeCounters.push_back (counterName); + uint32_t counterId = m_nodeCounters.size () - 1; // counter ID is zero-indexed + if(!m_onlineMode) + { + WriteXmlAddNodeCounter (counterId, counterName, counterType); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteAddNodeCounter (counterId, counterName, counterType)); + } + } + return counterId; +} + +uint32_t +AnimationInterface::AddResource (std::string resourcePath) +{ + m_resources.push_back (resourcePath); + uint32_t resourceId = m_resources.size () - 1; // resource ID is zero-indexed + if(!m_onlineMode) + { + WriteXmlAddResource (resourceId, resourcePath); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteAddResource (resourceId, resourcePath)); + } + } + return resourceId; +} + +void +AnimationInterface::EnablePacketMetadata (bool enable) +{ + m_enablePacketMetadata = enable; + if (enable) + { + Packet::EnablePrinting (); + } +} + +bool +AnimationInterface::IsInitialized () +{ + return initialized; +} + +bool +AnimationInterface::IsStarted () +{ + return m_started; +} + +void +AnimationInterface::SetAnimWriteCallback (AnimWriteCallback cb) +{ + m_writeCallback = cb; +} + +void +AnimationInterface::ResetAnimWriteCallback () +{ + m_writeCallback = 0; +} + +void +AnimationInterface::SetMobilityPollInterval (Time t) +{ + m_mobilityPollInterval = t; +} + + +void +AnimationInterface::SetConstantPosition (Ptr n, double x, double y, double z) +{ + NS_ASSERT (n); + Ptr loc = n->GetObject (); + if (loc == 0) + { + loc = CreateObject (); + n->AggregateObject (loc); + } + Vector hubVec (x, y, z); + loc->SetPosition (hubVec); + NS_LOG_INFO ("Node:" << n->GetId () << " Position set to:(" << x << "," << y << "," << z << ")"); + +} + +void +AnimationInterface::UpdateNodeImage (uint32_t nodeId, uint32_t resourceId) +{ + NS_LOG_INFO ("Setting node image for Node Id:" << nodeId); + if (resourceId > (m_resources.size ()-1)) + { + NS_FATAL_ERROR ("Resource Id:" << resourceId << " not found. Did you use AddResource?"); + } + if(!m_onlineMode) + { + WriteXmlUpdateNodeImage (nodeId, resourceId); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodeImage (nodeId, resourceId)); + } + } +} + +void +AnimationInterface::UpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counter) +{ + if (nodeCounterId > (m_nodeCounters.size () - 1)) + { + NS_FATAL_ERROR ("NodeCounter Id:" << nodeCounterId << " not found. Did you use AddNodeCounter?"); + } + if(!m_onlineMode) + { + WriteXmlUpdateNodeCounter (nodeCounterId, nodeId, counter); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodeCounter (nodeCounterId, nodeId, counter)); + } + } +} + +void +AnimationInterface::SetBackgroundImage (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity) +{ + if ((opacity < 0) || (opacity > 1)) + { + NS_FATAL_ERROR ("Opacity must be between 0.0 and 1.0"); + } + if(!m_onlineMode) + { + WriteXmlUpdateBackground (fileName, x, y, scaleX, scaleY, opacity); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateBackground (fileName, x, y, scaleX, scaleY, opacity)); + } + } +} + +void +AnimationInterface::UpdateNodeSize (uint32_t nodeId, double width, double height) +{ + AnimationInterface::NodeSize s = { width, height }; + m_nodeSizes[nodeId] = s; + if(!m_onlineMode) + { + WriteXmlUpdateNodeSize (nodeId, s.width, s.height); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodeSize (nodeId, s.width, s.height)); + } + } +} + +void +AnimationInterface::UpdateNodeColor (Ptr n, uint8_t r, uint8_t g, uint8_t b) +{ + UpdateNodeColor (n->GetId (), r, g, b); +} + +void +AnimationInterface::UpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b) +{ + NS_ASSERT (NodeList::GetNode (nodeId)); + NS_LOG_INFO ("Setting node color for Node Id:" << nodeId); + Rgb rgb = {r, g, b}; + m_nodeColors[nodeId] = rgb; + if(!m_onlineMode) + { + WriteXmlUpdateNodeColor (nodeId, r, g, b); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodeColor (nodeId, r, g, b)); + } + } +} + +void +AnimationInterface::UpdateLinkDescription (uint32_t fromNode, uint32_t toNode, + std::string linkDescription) +{ + if(!m_onlineMode) + { + WriteXmlUpdateLink (fromNode, toNode, linkDescription); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateLink (fromNode, toNode, linkDescription)); + } + } +} + +void +AnimationInterface::UpdateLinkDescription (Ptr fromNode, Ptr toNode, + std::string linkDescription) +{ + NS_ASSERT (fromNode); + NS_ASSERT (toNode); + if(!m_onlineMode) + { + WriteXmlUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateLink (fromNode->GetId (), toNode->GetId (), linkDescription)); + } + } +} + +void +AnimationInterface::UpdateNodeDescription (Ptr n, std::string descr) +{ + UpdateNodeDescription (n->GetId (), descr); +} + +void +AnimationInterface::UpdateNodeDescription (uint32_t nodeId, std::string descr) +{ + NS_ASSERT (NodeList::GetNode (nodeId)); + m_nodeDescriptions[nodeId] = descr; + if(!m_onlineMode) + { + WriteXmlUpdateNodeDescription (nodeId); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodeDescription (nodeId)); + } + } +} + +// Private methods + + +double +AnimationInterface::GetNodeEnergyFraction (Ptr node) const +{ + const EnergyFractionMap::const_iterator fractionIter = m_nodeEnergyFraction.find (node->GetId ()); + NS_ASSERT (fractionIter != m_nodeEnergyFraction.end ()); + return fractionIter->second; +} + +void +AnimationInterface::MobilityCourseChangeTrace (Ptr mobility) +{ + CHECK_STARTED_INTIMEWINDOW; + Ptr n = mobility->GetObject (); + NS_ASSERT (n); + Vector v ; + if (!mobility) + { + v = GetPosition (n); + } + else + { + v = mobility->GetPosition (); + } + UpdatePosition (n, v); + if(!m_onlineMode) + { + WriteXmlUpdateNodePosition (n->GetId (), v.x, v.y); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodePosition (n->GetId (), v.x, v.y)); + } + } +} + +bool +AnimationInterface::NodeHasMoved (Ptr n, Vector newLocation) +{ + Vector oldLocation = GetPosition (n); + bool moved = true; + if ((ceil (oldLocation.x) == ceil (newLocation.x)) && + (ceil (oldLocation.y) == ceil (newLocation.y))) + { + moved = false; + } + else + { + moved = true; + } + return moved; +} + +void +AnimationInterface::MobilityAutoCheck () +{ + CHECK_STARTED_INTIMEWINDOW; + std::vector > MovedNodes = GetMovedNodes (); + for (uint32_t i = 0; i < MovedNodes.size (); i++) + { + Ptr n = MovedNodes [i]; + NS_ASSERT (n); + Vector v = GetPosition (n); + if(!m_onlineMode) + { + WriteXmlUpdateNodePosition (n->GetId () , v.x, v.y); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteUpdateNodePosition (n->GetId () , v.x, v.y)); + } + } + } + if (!Simulator::IsFinished ()) + { + PurgePendingPackets (AnimationInterface::WIFI); + PurgePendingPackets (AnimationInterface::WIMAX); + PurgePendingPackets (AnimationInterface::LTE); + PurgePendingPackets (AnimationInterface::CSMA); + PurgePendingPackets (AnimationInterface::LRWPAN); + PurgePendingPackets (AnimationInterface::WAVE); + Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this); + } +} + +std::vector > +AnimationInterface::GetMovedNodes () +{ + std::vector < Ptr > movedNodes; + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + NS_ASSERT (n); + Ptr mobility = n->GetObject (); + Vector newLocation; + if (!mobility) + { + newLocation = GetPosition (n); + } + else + { + newLocation = mobility->GetPosition (); + } + if (!NodeHasMoved (n, newLocation)) + { + continue; //Location has not changed + } + else + { + UpdatePosition (n, newLocation); + movedNodes.push_back (n); + } + } + return movedNodes; +} + +int +AnimationInterface::WriteN (const std::string& st, FILE * f) +{ + if (!f) + { + return 0; + } + if (m_writeCallback) + { + m_writeCallback (st.c_str ()); + } + return WriteN (st.c_str (), st.length (), f); +} + +int +AnimationInterface::WriteN (const char* data, uint32_t count, FILE * f) +{ + if (!f) + { + return 0; + } + // Write count bytes to h from data + uint32_t nLeft = count; + const char* p = data; + uint32_t written = 0; + while (nLeft) + { + int n = std::fwrite (p, 1, nLeft, f); + if (n <= 0) + { + return written; + } + written += n; + nLeft -= n; + p += n; + } + return written; +} + +void +AnimationInterface::WriteRoutePath (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements) +{ + NS_LOG_INFO ("Writing Route Path From :" << nodeId << " To: " << destination.c_str ()); + if (!m_onlineMode) + WriteXmlRp (nodeId, destination, rpElements); + else + WriteRp (nodeId, destination, rpElements); + /*for (Ipv4RoutePathElements::const_iterator i = rpElements.begin (); + i != rpElements.end (); + ++i) + { + Ipv4RoutePathElement rpElement = *i; + NS_LOG_INFO ("Node:" << rpElement.nodeId << "-->" << rpElement.nextHop.c_str ()); + WriteN (GetXmlRp (rpElement.node, GetIpv4RoutingTable (n)), m_routingF); + + } + */ +} + +void +AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipv4Address, std::string channelType) +{ + if(!m_onlineMode) + { + WriteXmlNonP2pLinkProperties (id, ipv4Address, channelType); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteNonP2pLinkProperties (id, ipv4Address)); + } + } +} + +const std::vector +AnimationInterface::GetElementsFromContext (const std::string& context) const +{ + std::vector elements; + size_t pos1=0, pos2; + while (pos1 != context.npos) + { + pos1 = context.find ("/",pos1); + pos2 = context.find ("/",pos1+1); + elements.push_back (context.substr (pos1+1,pos2-(pos1+1))); + pos1 = pos2; + pos2 = context.npos; + } + return elements; +} + +Ptr +AnimationInterface::GetNodeFromContext (const std::string& context) const +{ + // Use "NodeList/*/ as reference + // where element [1] is the Node Id + + std::vector elements = GetElementsFromContext (context); + Ptr n = NodeList::GetNode (atoi (elements.at (1).c_str ())); + NS_ASSERT (n); + + return n; +} + +Ptr +AnimationInterface::GetNetDeviceFromContext (std::string context) +{ + // Use "NodeList/*/DeviceList/*/ as reference + // where element [1] is the Node Id + // element [2] is the NetDevice Id + + std::vector elements = GetElementsFromContext (context); + Ptr n = GetNodeFromContext (context); + + return n->GetDevice (atoi (elements.at (3).c_str ())); +} + +uint64_t +AnimationInterface::GetAnimUidFromPacket (Ptr p) +{ + AnimByteTag tag; + TypeId tid = tag.GetInstanceTypeId (); + ByteTagIterator i = p->GetByteTagIterator (); + bool found = false; + while (i.HasNext ()) + { + ByteTagIterator::Item item = i.Next (); + if (tid == item.GetTypeId ()) + { + item.GetTag (tag); + found = true; + } + } + if (found) + { + return tag.Get (); + } + else + { + return 0; + } +} + +void +AnimationInterface::AddByteTag (uint64_t animUid, Ptr p) +{ + AnimByteTag tag; + tag.Set (animUid); + p->AddByteTag (tag); +} + +void +AnimationInterface::RemainingEnergyTrace (std::string context, double previousEnergy, double currentEnergy) +{ + CHECK_STARTED_INTIMEWINDOW; + const Ptr node = GetNodeFromContext (context); + const uint32_t nodeId = node->GetId (); + + NS_LOG_INFO ("Remaining energy on one of sources on node " << nodeId << ": " << currentEnergy); + + const Ptr energySource = node->GetObject (); + + NS_ASSERT (energySource); + // Don't call GetEnergyFraction () because of recursion + const double energyFraction = currentEnergy / energySource->GetInitialEnergy (); + + NS_LOG_INFO ("Total energy fraction on node " << nodeId << ": " << energyFraction); + + m_nodeEnergyFraction[nodeId] = energyFraction; + UpdateNodeCounter (m_remainingEnergyCounterId, nodeId, energyFraction); +} + +void +AnimationInterface::WifiPhyTxDropTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeWifiPhyTxDrop[node->GetId ()]; +} + +void +AnimationInterface::WifiPhyRxDropTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeWifiPhyRxDrop[node->GetId ()]; +} + +void +AnimationInterface::WifiMacTxTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeWifiMacTx[node->GetId ()]; +} + +void +AnimationInterface::WifiMacTxDropTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeWifiMacTxDrop[node->GetId ()]; +} + +void +AnimationInterface::WifiMacRxTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeWifiMacRx[node->GetId ()]; +} + +void +AnimationInterface::WifiMacRxDropTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeWifiMacRxDrop[node->GetId ()]; +} + +void +AnimationInterface::LrWpanMacTxTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeLrWpanMacTx[node->GetId ()]; +} + +void +AnimationInterface::LrWpanMacTxDropTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeLrWpanMacTxDrop[node->GetId ()]; +} + +void +AnimationInterface::LrWpanMacRxTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeLrWpanMacRx[node->GetId ()]; +} + +void +AnimationInterface::LrWpanMacRxDropTrace (std::string context, Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeLrWpanMacRxDrop[node->GetId ()]; +} + +void +AnimationInterface::Ipv4TxTrace (std::string context, Ptr p, Ptr ipv4, uint32_t interfaceIndex) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeIpv4Tx[node->GetId ()]; +} + +void +AnimationInterface::Ipv4RxTrace (std::string context, Ptr p, Ptr ipv4, uint32_t interfaceIndex) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeIpv4Rx[node->GetId ()]; +} + +void +AnimationInterface::Ipv4DropTrace (std::string context, + const Ipv4Header & ipv4Header, + Ptr p, + Ipv4L3Protocol::DropReason dropReason, + Ptr ipv4, + uint32_t) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeIpv4Drop[node->GetId ()]; +} + +void +AnimationInterface::EnqueueTrace (std::string context, + Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeQueueEnqueue[node->GetId ()]; +} + +void +AnimationInterface::DequeueTrace (std::string context, + Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeQueueDequeue[node->GetId ()]; +} + +void +AnimationInterface::QueueDropTrace (std::string context, + Ptr p) +{ + const Ptr node = GetNodeFromContext (context); + ++m_nodeQueueDrop[node->GetId ()]; +} + +void +AnimationInterface::DevTxTrace (std::string context, + Ptr p, + Ptr tx, + Ptr rx, + Time txTime, + Time rxTime) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + NS_ASSERT (tx); + NS_ASSERT (rx); + Time now = Simulator::Now (); + double fbTx = now.GetSeconds (); + double lbTx = (now + txTime).GetSeconds (); + double fbRx = (now + rxTime - txTime).GetSeconds (); + double lbRx = (now + rxTime).GetSeconds (); + CheckMaxPktsPerTraceFile (); + if(m_onlineMode) + { + if(m_animxmlparser) + { + m_animxmlparser->doParse( + WriteP ("p", + tx->GetNode ()->GetId (), + fbTx, + lbTx, + rx->GetNode ()->GetId (), + fbRx, + lbRx, + m_enablePacketMetadata? GetPacketMetadata (p):"")); + } + } + else + { + WriteXmlP ("p", + tx->GetNode ()->GetId (), + fbTx, + lbTx, + rx->GetNode ()->GetId (), + fbRx, + lbRx, + m_enablePacketMetadata? GetPacketMetadata (p):""); + } +} + +void +AnimationInterface::GenericWirelessTxTrace (std::string context, Ptr p, ProtocolType protocolType) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + + ++gAnimUid; + NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessTxTrace for packet:" << gAnimUid); + AddByteTag (gAnimUid, p); + AnimPacketInfo pktInfo (ndev, Simulator::Now ()); + AddPendingPacket (protocolType, gAnimUid, pktInfo); + + Ptr netDevice = DynamicCast (ndev); + if (netDevice) + { + Mac48Address nodeAddr = netDevice->GetMac ()->GetAddress (); + std::ostringstream oss; + oss << nodeAddr; + Ptr n = netDevice->GetNode (); + NS_ASSERT (n); + m_macToNodeIdMap[oss.str ()] = n->GetId (); + NS_LOG_INFO ("Added Mac" << oss.str () << " node:" <at (gAnimUid), gAnimUid); +} + +void +AnimationInterface::GenericWirelessRxTrace (std::string context, Ptr p, ProtocolType protocolType) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO (ProtocolTypeToString (protocolType).c_str () << " for packet:" << animUid); + if (!IsPacketPending (animUid, protocolType)) + { + NS_LOG_WARN (ProtocolTypeToString (protocolType).c_str () << " GenericWirelessRxTrace: unknown Uid"); + return; + } + AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); + pendingPackets->at (animUid).ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + OutputWirelessPacketRxInfo (p, pendingPackets->at (animUid), animUid); +} + +void +AnimationInterface::UanPhyGenTxTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessTxTrace (context, p, AnimationInterface::UAN); +} + +void +AnimationInterface::UanPhyGenRxTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessRxTrace (context, p, AnimationInterface::UAN); +} + +void +AnimationInterface::WifiPhyTxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessTxTrace (context, p, AnimationInterface::WIFI); +} + +void +AnimationInterface::WifiPhyRxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("Wifi RxBeginTrace for packet:" << animUid); + if (!IsPacketPending (animUid, AnimationInterface::WIFI)) + { + NS_ASSERT (0); + NS_LOG_WARN ("WifiPhyRxBeginTrace: unknown Uid"); + std::ostringstream oss; + WifiMacHeader hdr; + if (!p->PeekHeader (hdr)) + { + NS_LOG_WARN ("WifiMacHeader not present"); + return; + } + oss << hdr.GetAddr2 (); + if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ()) + { + NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping"); + return; + } + Ptr txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]); + UpdatePosition (txNode); + AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]); + AddPendingPacket (AnimationInterface::WIFI, animUid, pktInfo); + NS_LOG_WARN ("WifiPhyRxBegin: unknown Uid, but we are adding a wifi packet"); + } + /// \todo NS_ASSERT (WifiPacketIsPending (animUid) == true); + m_pendingWifiPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + OutputWirelessPacketRxInfo (p, m_pendingWifiPackets[animUid], animUid); +} + +void +AnimationInterface::LrWpanPhyTxBeginTrace (std::string context, + Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr netDevice = DynamicCast (ndev); + + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + + UpdatePosition (n); + + LrWpanMacHeader hdr; + if (!p->PeekHeader (hdr)) + { + NS_LOG_WARN ("LrWpanMacHeader not present"); + return; + } + + std::ostringstream oss; + if (hdr.GetSrcAddrMode () == 2) + { + Mac16Address nodeAddr = netDevice->GetMac ()->GetShortAddress (); + oss << nodeAddr; + } + else if (hdr.GetSrcAddrMode () == 3) + { + Mac64Address nodeAddr = netDevice->GetMac ()->GetExtendedAddress (); + oss << nodeAddr; + } + else + { + NS_LOG_WARN ("LrWpanMacHeader without source address"); + return; + } + m_macToNodeIdMap[oss.str ()] = n->GetId (); + NS_LOG_INFO ("Added Mac" << oss.str () << " node:" < p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + + AnimByteTag tag; + if (!p->FindFirstMatchingByteTag (tag)) + { + return; + } + + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("LrWpan RxBeginTrace for packet:" << animUid); + if (!IsPacketPending (animUid, AnimationInterface::LRWPAN)) + { + NS_LOG_WARN ("LrWpanPhyRxBeginTrace: unknown Uid - most probably it's an ACK."); + } + + UpdatePosition (n); + m_pendingLrWpanPackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + OutputWirelessPacketRxInfo (p, m_pendingLrWpanPackets[animUid], animUid); +} + +void +AnimationInterface::WavePhyTxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessTxTrace (context, p, AnimationInterface::WAVE); +} + +void +AnimationInterface::WavePhyRxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("Wave RxBeginTrace for packet:" << animUid); + if (!IsPacketPending (animUid, AnimationInterface::WAVE)) + { + NS_ASSERT (0); + NS_LOG_WARN ("WavePhyRxBeginTrace: unknown Uid"); + std::ostringstream oss; + WifiMacHeader hdr; + if (!p->PeekHeader (hdr)) + { + NS_LOG_WARN ("WaveMacHeader not present"); + return; + } + oss << hdr.GetAddr2 (); + if (m_macToNodeIdMap.find (oss.str ()) == m_macToNodeIdMap.end ()) + { + NS_LOG_WARN ("Transmitter Mac address " << oss.str () << " never seen before. Skipping"); + return; + } + Ptr txNode = NodeList::GetNode (m_macToNodeIdMap[oss.str ()]); + UpdatePosition (txNode); + AnimPacketInfo pktInfo (0, Simulator::Now (), m_macToNodeIdMap[oss.str ()]); + AddPendingPacket (AnimationInterface::WAVE, animUid, pktInfo); + NS_LOG_WARN ("WavePhyRxBegin: unknown Uid, but we are adding a wave packet"); + } + /// \todo NS_ASSERT (WavePacketIsPending (animUid) == true); + m_pendingWavePackets[animUid].ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + OutputWirelessPacketRxInfo (p, m_pendingWavePackets[animUid], animUid); +} + + +void +AnimationInterface::WimaxTxTrace (std::string context, Ptr p, const Mac48Address & m) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessTxTrace (context, p, AnimationInterface::WIMAX); +} + + +void +AnimationInterface::WimaxRxTrace (std::string context, Ptr p, const Mac48Address & m) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessRxTrace (context, p, AnimationInterface::WIMAX); +} + +void +AnimationInterface::LteTxTrace (std::string context, Ptr p, const Mac48Address & m) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessTxTrace (context, p, AnimationInterface::LTE); +} + +void +AnimationInterface::LteRxTrace (std::string context, Ptr p, const Mac48Address & m) +{ + NS_LOG_FUNCTION (this); + return GenericWirelessRxTrace (context, p, AnimationInterface::LTE); +} + +void +AnimationInterface::LteSpectrumPhyTxStart (std::string context, Ptr pb) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + if (!pb) + { + NS_LOG_WARN ("pb == 0. Not yet supported"); + return; + } + context = "/" + context; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + + std::list > pbList = pb->GetPackets (); + for (std::list >::iterator i = pbList.begin (); + i != pbList.end (); + ++i) + { + Ptr p = *i; + ++gAnimUid; + NS_LOG_INFO ("LteSpectrumPhyTxTrace for packet:" << gAnimUid); + AnimPacketInfo pktInfo (ndev, Simulator::Now ()); + AddByteTag (gAnimUid, p); + AddPendingPacket (AnimationInterface::LTE, gAnimUid, pktInfo); + OutputWirelessPacketTxInfo (p, pktInfo, gAnimUid); + } +} + +void +AnimationInterface::LteSpectrumPhyRxStart (std::string context, Ptr pb) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + if (!pb) + { + NS_LOG_WARN ("pb == 0. Not yet supported"); + return; + } + context = "/" + context; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + + std::list > pbList = pb->GetPackets (); + for (std::list >::iterator i = pbList.begin (); + i != pbList.end (); + ++i) + { + Ptr p = *i; + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("LteSpectrumPhyRxTrace for packet:" << gAnimUid); + if (!IsPacketPending (animUid, AnimationInterface::LTE)) + { + NS_LOG_WARN ("LteSpectrumPhyRxTrace: unknown Uid"); + return; + } + AnimPacketInfo& pktInfo = m_pendingLtePackets[animUid]; + pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + OutputWirelessPacketRxInfo (p, pktInfo, animUid); + } +} + +void +AnimationInterface::CsmaPhyTxBeginTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + ++gAnimUid; + NS_LOG_INFO ("CsmaPhyTxBeginTrace for packet:" << gAnimUid); + AddByteTag (gAnimUid, p); + UpdatePosition (ndev); + AnimPacketInfo pktInfo (ndev, Simulator::Now ()); + AddPendingPacket (AnimationInterface::CSMA, gAnimUid, pktInfo); + + +} + +void +AnimationInterface::CsmaPhyTxEndTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + NS_LOG_INFO ("CsmaPhyTxEndTrace for packet:" << animUid); + if (!IsPacketPending (animUid, AnimationInterface::CSMA)) + { + NS_LOG_WARN ("CsmaPhyTxEndTrace: unknown Uid"); + NS_FATAL_ERROR ("CsmaPhyTxEndTrace: unknown Uid"); + AnimPacketInfo pktInfo (ndev, Simulator::Now ()); + AddPendingPacket (AnimationInterface::CSMA, animUid, pktInfo); + NS_LOG_WARN ("Unknown Uid, but adding Csma Packet anyway"); + } + /// \todo NS_ASSERT (IsPacketPending (AnimUid) == true); + AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid]; + pktInfo.m_lbTx = Simulator::Now ().GetSeconds (); +} + +void +AnimationInterface::CsmaPhyRxEndTrace (std::string context, Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + UpdatePosition (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + if (!IsPacketPending (animUid, AnimationInterface::CSMA)) + { + NS_LOG_WARN ("CsmaPhyRxEndTrace: unknown Uid"); + return; + } + /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); + AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid]; + pktInfo.ProcessRxBegin (ndev, Simulator::Now ().GetSeconds ()); + NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid); + NS_LOG_INFO ("CsmaPhyRxEndTrace for packet:" << animUid << " complete"); + OutputCsmaPacket (p, pktInfo); +} + +void +AnimationInterface::CsmaMacRxTrace (std::string context, + Ptr p) +{ + NS_LOG_FUNCTION (this); + CHECK_STARTED_INTIMEWINDOW_TRACKPACKETS; + Ptr ndev = GetNetDeviceFromContext (context); + NS_ASSERT (ndev); + uint64_t animUid = GetAnimUidFromPacket (p); + if (!IsPacketPending (animUid, AnimationInterface::CSMA)) + { + NS_LOG_WARN ("CsmaMacRxTrace: unknown Uid"); + return; + } + /// \todo NS_ASSERT (CsmaPacketIsPending (AnimUid) == true); + AnimPacketInfo& pktInfo = m_pendingCsmaPackets[animUid]; + NS_LOG_INFO ("MacRxTrace for packet:" << animUid << " complete"); + OutputCsmaPacket (p, pktInfo); +} + +void +AnimationInterface::OutputWirelessPacketTxInfo (Ptr p, AnimPacketInfo &pktInfo, uint64_t animUid) +{ + CheckMaxPktsPerTraceFile (); + uint32_t nodeId = 0; + if (pktInfo.m_txnd) + { + nodeId = pktInfo.m_txnd->GetNode ()->GetId (); + } + else + { + nodeId = pktInfo.m_txNodeId; + } + if(!m_onlineMode) + { + WriteXmlPRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):""); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WritePRef (animUid, nodeId, pktInfo.m_fbTx, m_enablePacketMetadata? GetPacketMetadata (p):"")); + } + } +} + +void +AnimationInterface::OutputWirelessPacketRxInfo (Ptr p, AnimPacketInfo & pktInfo, uint64_t animUid) +{ + CheckMaxPktsPerTraceFile (); + uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId (); + if(!m_onlineMode) + { + WriteXmlP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteP (animUid, "wpr", rxId, pktInfo.m_fbRx, pktInfo.m_lbRx)); + } + } +} + +void +AnimationInterface::OutputCsmaPacket (Ptr p, AnimPacketInfo &pktInfo) +{ + CheckMaxPktsPerTraceFile (); + NS_ASSERT (pktInfo.m_txnd); + uint32_t nodeId = pktInfo.m_txnd->GetNode ()->GetId (); + uint32_t rxId = pktInfo.m_rxnd->GetNode ()->GetId (); + if(!m_onlineMode) + { + WriteXmlP ("p", + nodeId, + pktInfo.m_fbTx, + pktInfo.m_lbTx, + rxId, + pktInfo.m_fbRx, + pktInfo.m_lbRx, + m_enablePacketMetadata? GetPacketMetadata (p):""); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteP ("p", + nodeId, + pktInfo.m_fbTx, + pktInfo.m_lbTx, + rxId, + pktInfo.m_fbRx, + pktInfo.m_lbRx, + m_enablePacketMetadata? GetPacketMetadata (p):"")); + } + } +} + +void +AnimationInterface::AddPendingPacket (ProtocolType protocolType, uint64_t animUid, AnimPacketInfo pktInfo) +{ + AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); + NS_ASSERT (pendingPackets); + pendingPackets->insert (AnimUidPacketInfoMap::value_type (animUid, pktInfo)); +} + +bool +AnimationInterface::IsPacketPending (uint64_t animUid, AnimationInterface::ProtocolType protocolType) +{ + AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); + NS_ASSERT (pendingPackets); + return (pendingPackets->find (animUid) != pendingPackets->end ()); +} + +void +AnimationInterface::PurgePendingPackets (AnimationInterface::ProtocolType protocolType) +{ + AnimUidPacketInfoMap * pendingPackets = ProtocolTypeToPendingPackets (protocolType); + NS_ASSERT (pendingPackets); + if (pendingPackets->empty ()) + { + return; + } + std::vector purgeList; + for (AnimUidPacketInfoMap::iterator i = pendingPackets->begin (); + i != pendingPackets->end (); + ++i) + { + + AnimPacketInfo pktInfo = i->second; + double delta = (Simulator::Now ().GetSeconds () - pktInfo.m_fbTx); + if (delta > PURGE_INTERVAL) + { + purgeList.push_back (i->first); + } + } + for (std::vector ::iterator i = purgeList.begin (); + i != purgeList.end (); + ++i) + { + pendingPackets->erase (*i); + } +} + +AnimationInterface::AnimUidPacketInfoMap * +AnimationInterface::ProtocolTypeToPendingPackets (AnimationInterface::ProtocolType protocolType) +{ + AnimUidPacketInfoMap * pendingPackets = 0; + switch (protocolType) + { + case AnimationInterface::WIFI: + { + pendingPackets = &m_pendingWifiPackets; + break; + } + case AnimationInterface::UAN: + { + pendingPackets = &m_pendingUanPackets; + break; + } + case AnimationInterface::CSMA: + { + pendingPackets = &m_pendingCsmaPackets; + break; + } + case AnimationInterface::WIMAX: + { + pendingPackets = &m_pendingWimaxPackets; + break; + } + case AnimationInterface::LTE: + { + pendingPackets = &m_pendingLtePackets; + break; + } + case AnimationInterface::LRWPAN: + { + pendingPackets = &m_pendingLrWpanPackets; + break; + } + case AnimationInterface::WAVE: + { + pendingPackets = &m_pendingWavePackets; + break; + } + } + return pendingPackets; + +} + +std::string +AnimationInterface::ProtocolTypeToString (AnimationInterface::ProtocolType protocolType) +{ + std::string result = "Unknown"; + switch (protocolType) + { + case AnimationInterface::WIFI: + { + result = "WIFI"; + break; + } + case AnimationInterface::UAN: + { + result = "UAN"; + break; + } + case AnimationInterface::CSMA: + { + result = "CSMA"; + break; + } + case AnimationInterface::WIMAX: + { + result = "WIMAX"; + break; + } + case AnimationInterface::LTE: + { + result = "LTE"; + break; + } + case AnimationInterface::LRWPAN: + { + result = "LRWPAN"; + break; + } + case AnimationInterface::WAVE: + { + result = "WAVE"; + break; + } + } + return result; +} + +// Counters + +std::string +AnimationInterface::CounterTypeToString (CounterType counterType) +{ + std::string typeString = "unknown"; + switch (counterType) + { + case UINT32_COUNTER: + { + typeString = "UINT32"; + break; + } + case DOUBLE_COUNTER: + { + typeString = "DOUBLE"; + break; + } + } + return typeString; +} + +// General + +std::string +AnimationInterface::GetPacketMetadata (Ptr p) +{ + std::ostringstream oss; + p->Print (oss); + return oss.str (); +} + +uint64_t +AnimationInterface::GetTracePktCount () +{ + return m_currentPktCount; +} + +void +AnimationInterface::StopAnimation (bool onlyAnimation) +{ + m_started = false; + NS_LOG_INFO ("Stopping Animation"); + ResetAnimWriteCallback (); + if (m_f) + { + if(!m_onlineMode) + { + // Terminate the anim element + WriteXmlClose ("anim"); + } + std::fclose (m_f); + m_f = 0; + } + if (onlyAnimation) + { + return; + } + if (m_routingF) + { + if(!m_onlineMode) + { + WriteXmlClose ("anim", true); + } + std::fclose (m_routingF); + m_routingF = 0; + } +} + +void +AnimationInterface::StartAnimation (bool restart) +{ + m_currentPktCount = 0; + m_started = true; + if(m_onlineMode) + { + WriteAnim (); + } + else + { + SetOutputFile (m_outputFileName); + WriteXmlAnim (); + } + WriteNodes (); + WriteNodeColors (); + WriteLinkProperties (); + WriteIpv4Addresses (); + WriteIpv6Addresses (); + WriteNodeSizes (); + WriteNodeEnergies (); + if (!restart) + { + Simulator::Schedule (m_mobilityPollInterval, &AnimationInterface::MobilityAutoCheck, this); + ConnectCallbacks (); + } +} + +void +AnimationInterface::AddToIpv4AddressNodeIdTable (std::string ipv4Address, uint32_t nodeId) +{ + m_ipv4ToNodeIdMap[ipv4Address] = nodeId; + m_nodeIdIpv4Map.insert(NodeIdIpv4Pair(nodeId, ipv4Address)); +} + +void +AnimationInterface::AddToIpv4AddressNodeIdTable (std::vector ipv4Addresses, uint32_t nodeId) +{ + for (std::vector::const_iterator i = ipv4Addresses.begin (); + i != ipv4Addresses.end (); + ++i) + { + AddToIpv4AddressNodeIdTable (*i, nodeId); + } +} + +void +AnimationInterface::AddToIpv6AddressNodeIdTable(std::string ipv6Address, uint32_t nodeId) +{ + m_ipv6ToNodeIdMap[ipv6Address] = nodeId; + m_nodeIdIpv6Map.insert(NodeIdIpv6Pair(nodeId, ipv6Address)); +} + +void +AnimationInterface::AddToIpv6AddressNodeIdTable(std::vector ipv6Addresses, uint32_t nodeId) +{ + for (std::vector::const_iterator i = ipv6Addresses.begin(); + i != ipv6Addresses.end(); + ++i) + { + AddToIpv6AddressNodeIdTable(*i, nodeId); + } +} + +// Callbacks +void +AnimationInterface::ConnectLteEnb (Ptr n, Ptr nd, uint32_t devIndex) +{ + + Ptr lteEnbPhy = nd->GetPhy (); + Ptr dlPhy = lteEnbPhy->GetDownlinkSpectrumPhy (); + Ptr ulPhy = lteEnbPhy->GetUplinkSpectrumPhy (); + std::ostringstream oss; + //NodeList/*/DeviceList/*/ + oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/"; + if (dlPhy) + { + dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } + if (ulPhy) + { + ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } +} + + + +void +AnimationInterface::ConnectLteUe (Ptr n, Ptr nd, uint32_t devIndex) +{ + + Ptr lteUePhy = nd->GetPhy (); + Ptr dlPhy = lteUePhy->GetDownlinkSpectrumPhy (); + Ptr ulPhy = lteUePhy->GetUplinkSpectrumPhy (); + std::ostringstream oss; + //NodeList/*/DeviceList/*/ + oss << "NodeList/" << n->GetId () << "/DeviceList/" << devIndex << "/"; + if (dlPhy) + { + dlPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + dlPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } + if (ulPhy) + { + ulPhy->TraceConnect ("TxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyTxStart, this)); + ulPhy->TraceConnect ("RxStart", oss.str (), MakeCallback (&AnimationInterface::LteSpectrumPhyRxStart, this)); + } +} + +void +AnimationInterface::ConnectLte () +{ + + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + NS_ASSERT (n); + uint32_t nDevices = n->GetNDevices (); + for (uint32_t devIndex = 0; devIndex < nDevices; ++devIndex) + { + Ptr nd = n->GetDevice (devIndex); + if (!nd) + continue; + Ptr lteUeNetDevice = DynamicCast (nd); + if (lteUeNetDevice) + { + ConnectLteUe (n, lteUeNetDevice, devIndex); + continue; + } + Ptr lteEnbNetDevice = DynamicCast (nd); + if (lteEnbNetDevice) + ConnectLteEnb (n, lteEnbNetDevice, devIndex); + } + + } +} + +void +AnimationInterface::ConnectCallbacks () +{ + // Connect the callbacks + Config::Connect ("/ChannelList/*/TxRxPointToPoint", + MakeCallback (&AnimationInterface::DevTxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxBegin", + MakeCallback (&AnimationInterface::WifiPhyTxBeginTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxBegin", + MakeCallback (&AnimationInterface::WifiPhyRxBeginTrace, this)); + Config::ConnectWithoutContext ("/NodeList/*/$ns3::MobilityModel/CourseChange", + MakeCallback (&AnimationInterface::MobilityCourseChangeTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Tx", + MakeCallback (&AnimationInterface::WimaxTxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WimaxNetDevice/Rx", + MakeCallback (&AnimationInterface::WimaxRxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Tx", + MakeCallback (&AnimationInterface::LteTxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LteNetDevice/Rx", + MakeCallback (&AnimationInterface::LteRxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxBegin", + MakeCallback (&AnimationInterface::CsmaPhyTxBeginTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyTxEnd", + MakeCallback (&AnimationInterface::CsmaPhyTxEndTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/PhyRxEnd", + MakeCallback (&AnimationInterface::CsmaPhyRxEndTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/MacRx", + MakeCallback (&AnimationInterface::CsmaMacRxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyTxBegin", + MakeCallback (&AnimationInterface::UanPhyGenTxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::UanNetDevice/Phy/PhyRxBegin", + MakeCallback (&AnimationInterface::UanPhyGenRxTrace, this)); + Config::Connect ("/NodeList/*/$ns3::BasicEnergySource/RemainingEnergy", + MakeCallback (&AnimationInterface::RemainingEnergyTrace, this)); + + ConnectLte (); + + Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx", + MakeCallback (&AnimationInterface::Ipv4TxTrace, this)); + Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx", + MakeCallback (&AnimationInterface::Ipv4RxTrace, this)); + Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Drop", + MakeCallback (&AnimationInterface::Ipv4DropTrace, this)); + + // Queue Enqueues + + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Enqueue", + MakeCallback (&AnimationInterface::EnqueueTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Enqueue", + MakeCallback (&AnimationInterface::EnqueueTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Enqueue", + MakeCallback (&AnimationInterface::EnqueueTrace, this)); + + // Queue Dequeues + + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Dequeue", + MakeCallback (&AnimationInterface::DequeueTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Dequeue", + MakeCallback (&AnimationInterface::DequeueTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Dequeue", + MakeCallback (&AnimationInterface::DequeueTrace, this)); + + // Queue Drops + + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::AlohaNoackNetDevice/Queue/Drop", + MakeCallback (&AnimationInterface::QueueDropTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::CsmaNetDevice/TxQueue/Drop", + MakeCallback (&AnimationInterface::QueueDropTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/TxQueue/Drop", + MakeCallback (&AnimationInterface::QueueDropTrace, this)); + + + // Wifi Mac + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx", + MakeCallback (&AnimationInterface::WifiMacTxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop", + MakeCallback (&AnimationInterface::WifiMacTxDropTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx", + MakeCallback (&AnimationInterface::WifiMacRxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop", + MakeCallback (&AnimationInterface::WifiMacRxDropTrace, this)); + + // Wifi Phy + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxDrop", + MakeCallback (&AnimationInterface::WifiPhyTxDropTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxDrop", + MakeCallback (&AnimationInterface::WifiPhyRxDropTrace, this)); + + // LrWpan + Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyTxBegin", + MakeCallback (&AnimationInterface::LrWpanPhyTxBeginTrace, this)); + Config::Connect ("NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Phy/PhyRxBegin", + MakeCallback (&AnimationInterface::LrWpanPhyRxBeginTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTx", + MakeCallback (&AnimationInterface::LrWpanMacTxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacTxDrop", + MakeCallback (&AnimationInterface::LrWpanMacTxDropTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRx", + MakeCallback (&AnimationInterface::LrWpanMacRxTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::LrWpanNetDevice/Mac/MacRxDrop", + MakeCallback (&AnimationInterface::LrWpanMacRxDropTrace, this)); + + // Wave + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyTxBegin", + MakeCallback (&AnimationInterface::WavePhyTxBeginTrace, this)); + Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/$ns3::WifiPhy/PhyRxBegin", + MakeCallback (&AnimationInterface::WavePhyRxBeginTrace, this)); +} + +Vector +AnimationInterface::UpdatePosition (Ptr n) +{ + Ptr loc = n->GetObject (); + if (loc) + { + m_nodeLocation[n->GetId ()] = loc->GetPosition (); + } + else + { + NS_LOG_UNCOND ( "AnimationInterface WARNING:Node:" << n->GetId () << " Does not have a mobility model. Use SetConstantPosition if it is stationary"); + Ptr x = CreateObject (); + x->SetAttribute ("Min", DoubleValue (0)); + x->SetAttribute ("Max", DoubleValue (100)); + Ptr y = CreateObject (); + y->SetAttribute ("Min", DoubleValue (0)); + y->SetAttribute ("Max", DoubleValue (100)); + m_nodeLocation[n->GetId ()] = Vector (int (x->GetValue ()), int (y->GetValue ()), 0); + } + return m_nodeLocation[n->GetId ()]; +} + +Vector +AnimationInterface::UpdatePosition (Ptr n, Vector v) +{ + m_nodeLocation[n->GetId ()] = v; + return v; +} + +Vector +AnimationInterface::UpdatePosition (Ptr ndev) +{ + Ptr n = ndev->GetNode (); + NS_ASSERT (n); + return UpdatePosition (n); +} + +Vector +AnimationInterface::GetPosition (Ptr n) +{ + if (m_nodeLocation.find (n->GetId ()) == m_nodeLocation.end ()) + { + NS_FATAL_ERROR ("Node:" <GetId () << " not found in Location table"); + } + return m_nodeLocation[n->GetId ()]; +} + + +std::string +AnimationInterface::GetMacAddress (Ptr nd) +{ + Address nodeAddr = nd->GetAddress (); + std::ostringstream oss; + oss << nodeAddr; + return oss.str ().substr (6); // Skip the first 6 chars to get the Mac +} + +std::string +AnimationInterface::GetIpv4Address (Ptr nd) +{ + Ptr ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject (); + if (!ipv4) + { + NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found"); + return "0.0.0.0"; + } + int32_t ifIndex = ipv4->GetInterfaceForDevice (nd); + if (ifIndex == -1) + { + NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice"); + return "0.0.0.0"; + } + Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, 0); + std::ostringstream oss; + oss << addr.GetLocal (); + return oss.str (); +} + +std::string +AnimationInterface::GetIpv6Address(Ptr nd) +{ + Ptr ipv6 = NodeList::GetNode(nd->GetNode()->GetId())->GetObject (); + if (!ipv6) + { + NS_LOG_WARN("Node: " << nd->GetNode()->GetId() << " No ipv4 object found"); + return "::"; + } + int32_t ifIndex = ipv6->GetInterfaceForDevice(nd); + if (ifIndex == -1) + { + NS_LOG_WARN("Node :" << nd->GetNode()->GetId() << " Could not find index of NetDevice"); + return "::"; + } + bool nonLinkLocalFound = false; + uint32_t nAddresses = ipv6->GetNAddresses(ifIndex); + Ipv6InterfaceAddress addr; + for (uint32_t addressIndex = 0; addressIndex < nAddresses; ++addressIndex) + { + addr = ipv6->GetAddress(ifIndex, addressIndex); + if (!addr.GetAddress().IsLinkLocal()) + { + nonLinkLocalFound = true; + break; + } + } + if (!nonLinkLocalFound) + addr = ipv6->GetAddress(ifIndex, 0); + std::ostringstream oss; + oss << addr.GetAddress(); + return oss.str(); +} + + + +std::vector +AnimationInterface::GetIpv4Addresses (Ptr nd) +{ + std::vector ipv4Addresses; + Ptr ipv4 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject (); + if (!ipv4) + { + NS_LOG_WARN ("Node: " << nd->GetNode ()->GetId () << " No ipv4 object found"); + return ipv4Addresses; + } + int32_t ifIndex = ipv4->GetInterfaceForDevice (nd); + if (ifIndex == -1) + { + NS_LOG_WARN ("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice"); + return ipv4Addresses; + } + for (uint32_t index = 0; index < ipv4->GetNAddresses (ifIndex); ++index) + { + Ipv4InterfaceAddress addr = ipv4->GetAddress (ifIndex, index); + std::ostringstream oss; + oss << addr.GetLocal (); + ipv4Addresses.push_back(oss.str ()); + } + return ipv4Addresses; +} + +std::vector +AnimationInterface::GetIpv6Addresses(Ptr nd) +{ + std::vector ipv6Addresses; + Ptr ipv6 = NodeList::GetNode (nd->GetNode ()->GetId ())->GetObject (); + if (!ipv6) + { + NS_LOG_WARN("Node: " << nd->GetNode ()->GetId () << " No ipv6 object found"); + return ipv6Addresses; + } + int32_t ifIndex = ipv6->GetInterfaceForDevice (nd); + if (ifIndex == -1) + { + NS_LOG_WARN("Node :" << nd->GetNode ()->GetId () << " Could not find index of NetDevice"); + return ipv6Addresses; + } + for (uint32_t index = 0; index < ipv6->GetNAddresses (ifIndex); ++index) + { + Ipv6InterfaceAddress addr = ipv6->GetAddress (ifIndex, index); + std::ostringstream oss; + oss << addr.GetAddress (); + ipv6Addresses.push_back (oss.str ()); + } + return ipv6Addresses; +} + + +void +AnimationInterface::WriteIpv4Addresses () +{ + for (NodeIdIpv4Map::const_iterator i = m_nodeIdIpv4Map.begin (); + i != m_nodeIdIpv4Map.end(); + ++i) + { + std::vector ipv4Addresses; + std::pair iterPair = m_nodeIdIpv4Map.equal_range (i->first); + for (NodeIdIpv4Map::const_iterator it = iterPair.first; + it != iterPair.second; + ++it) + { + ipv4Addresses.push_back (it->second); + } + if(!m_onlineMode){ + WriteXmlIpv4Addresses (i->first, ipv4Addresses); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteIpv4Addresses (i->first, ipv4Addresses)); + } + } + } +} + +void +AnimationInterface::WriteIpv6Addresses() +{ + for (NodeIdIpv6Map::const_iterator i = m_nodeIdIpv6Map.begin (); + i != m_nodeIdIpv6Map.end (); + i = m_nodeIdIpv6Map.upper_bound (i->first)) + { + std::vector ipv6Addresses; + std::pair iterPair = m_nodeIdIpv6Map.equal_range (i->first); + for (NodeIdIpv6Map::const_iterator it = iterPair.first; + it != iterPair.second; + ++it) + { + ipv6Addresses.push_back (it->second); + } + if(!m_onlineMode){ + WriteXmlIpv6Addresses (i->first, ipv6Addresses); + } + else + { + if(m_animxmlparser) + { + m_animxmlparser->doParse(WriteIpv6Addresses (i->first, ipv6Addresses)); + } + } + } +} + +void +AnimationInterface::WriteLinkProperties () +{ + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + UpdatePosition (n); + uint32_t n1Id = n->GetId (); + uint32_t nDev = n->GetNDevices (); // Number of devices + for (uint32_t i = 0; i < nDev; ++i) + { + Ptr dev = n->GetDevice (i); + NS_ASSERT (dev); + Ptr ch = dev->GetChannel (); + std::string channelType = "Unknown channel"; + if (ch) + { + channelType = ch->GetInstanceTypeId ().GetName (); + } + NS_LOG_DEBUG("Got ChannelType" << channelType); + + if (!ch || (channelType != std::string("ns3::PointToPointChannel"))) + { + NS_LOG_DEBUG ("No channel can't be a p2p device"); + /* + // Try to see if it is an LTE NetDevice, which does not return a channel + if ((dev->GetInstanceTypeId ().GetName () == "ns3::LteUeNetDevice") || + (dev->GetInstanceTypeId ().GetName () == "ns3::LteEnbNetDevice")|| + (dev->GetInstanceTypeId ().GetName () == "ns3::VirtualNetDevice")) + { + WriteNonP2pLinkProperties (n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType); + AddToIpv4AddressNodeIdTable (GetIpv4Address (dev), n->GetId ()); + } + */ + std::vector ipv4Addresses = GetIpv4Addresses (dev); + AddToIpv4AddressNodeIdTable(ipv4Addresses, n->GetId ()); + std::vector ipv6Addresses = GetIpv6Addresses (dev); + AddToIpv6AddressNodeIdTable(ipv6Addresses, n->GetId ()); + if (!ipv4Addresses.empty ()) + { + NS_LOG_INFO ("Writing Ipv4 link"); + WriteNonP2pLinkProperties(n->GetId (), GetIpv4Address (dev) + "~" + GetMacAddress (dev), channelType); + } + else if (!ipv6Addresses.empty ()) + { + NS_LOG_INFO ("Writing Ipv6 link"); + WriteNonP2pLinkProperties(n->GetId (), GetIpv6Address (dev) + "~" + GetMacAddress (dev), channelType); + } + continue; + } + + else if (channelType == std::string ("ns3::PointToPointChannel")) + { // Since these are duplex links, we only need to dump + // if srcid < dstid + uint32_t nChDev = ch->GetNDevices (); + for (uint32_t j = 0; j < nChDev; ++j) + { + Ptr chDev = ch->GetDevice (j); + uint32_t n2Id = chDev->GetNode ()->GetId (); + if (n1Id < n2Id) + { + + std::vector ipv4Addresses = GetIpv4Addresses (dev); + AddToIpv4AddressNodeIdTable (ipv4Addresses, n1Id); + ipv4Addresses = GetIpv4Addresses (chDev); + AddToIpv4AddressNodeIdTable (ipv4Addresses, n2Id); + std::vector ipv6Addresses = GetIpv6Addresses (dev); + AddToIpv6AddressNodeIdTable(ipv6Addresses, n1Id); + ipv6Addresses = GetIpv6Addresses (chDev); + AddToIpv6AddressNodeIdTable(ipv6Addresses, n2Id); + + P2pLinkNodeIdPair p2pPair; + p2pPair.fromNode = n1Id; + p2pPair.toNode = n2Id; + if (!ipv4Addresses.empty ()) + { + LinkProperties lp = { GetIpv4Address (dev) + "~" + GetMacAddress (dev), GetIpv4Address (chDev) + "~" + GetMacAddress (chDev), "" }; + m_linkProperties[p2pPair] = lp; + } + else if (!ipv6Addresses.empty ()) + { + LinkProperties lp = { GetIpv6Address (dev) + "~" + GetMacAddress (dev), GetIpv6Address (chDev) + "~" + GetMacAddress (chDev), "" }; + m_linkProperties[p2pPair] = lp; + } + if(!m_onlineMode) + { + WriteXmlLink (n1Id, 0, n2Id); + } + else + { + if(m_animxmlparser){ + m_animxmlparser->doParse(WriteLink(n1Id, 0, n2Id)); + } + } + } + } + } + } + } + m_linkProperties.clear (); +} + +void +AnimationInterface::WriteNodes () +{ + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + NS_LOG_INFO ("Update Position for Node: " << n->GetId ()); + Vector v = UpdatePosition (n); + if(!m_onlineMode) + { + WriteXmlNode (n->GetId (), n->GetSystemId (), v.x, v.y); + } + else + { + if(m_animxmlparser){ + m_animxmlparser->doParse(WriteNode(n->GetId (), n->GetSystemId (), v.x, v.y)); + } + } + } +} + +void +AnimationInterface::WriteNodeColors () +{ + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + Rgb rgb = {255, 0, 0}; + if (m_nodeColors.find (n->GetId ()) == m_nodeColors.end ()) + { + m_nodeColors[n->GetId ()] = rgb; + } + UpdateNodeColor (n, rgb.r, rgb.g, rgb.b); + } +} + +void +AnimationInterface::WriteNodeSizes () +{ + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + NS_LOG_INFO ("Update Size for Node: " << n->GetId ()); + AnimationInterface::NodeSize s = { 1, 1 }; + m_nodeSizes[n->GetId ()] = s; + UpdateNodeSize (n->GetId (), s.width, s.height); + } +} + +void +AnimationInterface::WriteNodeEnergies () +{ + m_remainingEnergyCounterId = AddNodeCounter ("RemainingEnergy", AnimationInterface::DOUBLE_COUNTER); + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + if (NodeList::GetNode (n->GetId ())->GetObject ()) + { + UpdateNodeCounter (m_remainingEnergyCounterId, n->GetId (), 1); + } + } +} + +bool +AnimationInterface::IsInTimeWindow () +{ + if ((Simulator::Now () >= m_startTime) && + (Simulator::Now () <= m_stopTime)) + return true; + else + return false; +} + +void +AnimationInterface::SetOutputFile (const std::string& fn, bool routing) +{ + if (!routing && m_f) + { + return; + } + if (routing && m_routingF) + { + NS_FATAL_ERROR ("SetRoutingOutputFile already used once"); + return; + } + + NS_LOG_INFO ("Creating new trace file:" << fn.c_str ()); + FILE * f = 0; + f = std::fopen (fn.c_str (), "w"); + if (!f) + { + NS_FATAL_ERROR ("Unable to open output file:" << fn.c_str ()); + return; // Can't open output file + } + if (routing) + { + m_routingF = f; + m_routingFileName = fn; + } + else + { + m_f = f; + m_outputFileName = fn; + } + return; +} + +void +AnimationInterface::CheckMaxPktsPerTraceFile () +{ + // Start a new trace file if the current packet count exceeded nax packets per file + ++m_currentPktCount; + if (m_currentPktCount <= m_maxPktsPerFile) + { + return; + } + NS_LOG_UNCOND ("Max Packets per trace file exceeded"); + StopAnimation (true); +} + +std::string +AnimationInterface::GetNetAnimVersion () +{ + return NETANIM_VERSION; +} + + +void +AnimationInterface::TrackQueueCounters () +{ + if (Simulator::Now () > m_queueCountersStopTime) + { + NS_LOG_INFO ("TrackQueueCounters Completed"); + return; + } + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + uint32_t nodeId = Ptr (*i)->GetId (); + UpdateNodeCounter (m_queueEnqueueCounterId, nodeId, m_nodeQueueEnqueue[nodeId]); + UpdateNodeCounter (m_queueDequeueCounterId, nodeId, m_nodeQueueDequeue[nodeId]); + UpdateNodeCounter (m_queueDropCounterId, nodeId, m_nodeQueueDrop[nodeId]); + } + Simulator::Schedule (m_queueCountersPollInterval, &AnimationInterface::TrackQueueCounters, this); +} + +void +AnimationInterface::TrackWifiMacCounters () +{ + if (Simulator::Now () > m_wifiMacCountersStopTime) + { + NS_LOG_INFO ("TrackWifiMacCounters Completed"); + return; + } + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + uint32_t nodeId = Ptr (*i)->GetId (); + UpdateNodeCounter (m_wifiMacTxCounterId, nodeId, m_nodeWifiMacTx[nodeId]); + UpdateNodeCounter (m_wifiMacTxDropCounterId, nodeId, m_nodeWifiMacTxDrop[nodeId]); + UpdateNodeCounter (m_wifiMacRxCounterId, nodeId, m_nodeWifiMacRx[nodeId]); + UpdateNodeCounter (m_wifiMacRxDropCounterId, nodeId, m_nodeWifiMacRxDrop[nodeId]); + } + Simulator::Schedule (m_wifiMacCountersPollInterval, &AnimationInterface::TrackWifiMacCounters, this); +} + +void +AnimationInterface::TrackWifiPhyCounters () +{ + if (Simulator::Now () > m_wifiPhyCountersStopTime) + { + NS_LOG_INFO ("TrackWifiPhyCounters Completed"); + return; + } + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + uint32_t nodeId = Ptr (*i)->GetId (); + UpdateNodeCounter (m_wifiPhyTxDropCounterId, nodeId, m_nodeWifiPhyTxDrop[nodeId]); + UpdateNodeCounter (m_wifiPhyRxDropCounterId, nodeId, m_nodeWifiPhyRxDrop[nodeId]); + } + Simulator::Schedule (m_wifiPhyCountersPollInterval, &AnimationInterface::TrackWifiPhyCounters, this); +} + +void +AnimationInterface::TrackIpv4L3ProtocolCounters () +{ + if (Simulator::Now () > m_ipv4L3ProtocolCountersStopTime) + { + NS_LOG_INFO ("TrackIpv4L3ProtocolCounters Completed"); + return; + } + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + uint32_t nodeId = Ptr (*i)->GetId (); + UpdateNodeCounter (m_ipv4L3ProtocolTxCounterId, nodeId, m_nodeIpv4Tx[nodeId]); + UpdateNodeCounter (m_ipv4L3ProtocolRxCounterId, nodeId, m_nodeIpv4Rx[nodeId]); + UpdateNodeCounter (m_ipv4L3ProtocolDropCounterId, nodeId, m_nodeIpv4Drop[nodeId]); + } + Simulator::Schedule (m_ipv4L3ProtocolCountersPollInterval, &AnimationInterface::TrackIpv4L3ProtocolCounters, this); +} + + + + + +/***** Routing-related *****/ + +void +AnimationInterface::TrackIpv4RoutePaths () +{ + if (m_ipv4RouteTrackElements.empty ()) + { + return; + } + for (std::vector ::const_iterator i = m_ipv4RouteTrackElements.begin (); + i != m_ipv4RouteTrackElements.end (); + ++i) + { + Ipv4RouteTrackElement trackElement = *i; + Ptr fromNode = NodeList::GetNode (trackElement.fromNodeId); + if (!fromNode) + { + NS_FATAL_ERROR ("Node: " << trackElement.fromNodeId << " Not found"); + continue; + } + Ptr ipv4 = fromNode->GetObject (); + if (!ipv4) + { + NS_LOG_WARN ("ipv4 object not found"); + continue; + } + Ptr rp = ipv4->GetRoutingProtocol (); + if (!rp) + { + NS_LOG_WARN ("Routing protocol object not found"); + continue; + } + NS_LOG_INFO ("Begin Track Route for: " << trackElement.destination.c_str () << " From:" << trackElement.fromNodeId); + Ptr pkt = Create (); + Ipv4Header header; + header.SetDestination (Ipv4Address (trackElement.destination.c_str ())); + Socket::SocketErrno sockerr; + Ptr rt = rp->RouteOutput (pkt, header, 0, sockerr); + Ipv4RoutePathElements rpElements; + if (!rt) + { + NS_LOG_INFO ("No route to :" << trackElement.destination.c_str ()); + Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" }; + rpElements.push_back (elem); + WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements); + continue; + } + std::ostringstream oss; + oss << rt->GetGateway (); + NS_LOG_INFO ("Node:" << trackElement.fromNodeId << "-->" << rt->GetGateway ()); + if (rt->GetGateway () == "0.0.0.0") + { + Ipv4RoutePathElement elem = { trackElement.fromNodeId, "C" }; + rpElements.push_back (elem); + if ( m_ipv4ToNodeIdMap.find (trackElement.destination) != m_ipv4ToNodeIdMap.end ()) + { + Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[trackElement.destination], "L" }; + rpElements.push_back (elem2); + } + } + else if (rt->GetGateway () == "127.0.0.1") + { + Ipv4RoutePathElement elem = { trackElement.fromNodeId, "-1" }; + rpElements.push_back (elem); + } + else + { + Ipv4RoutePathElement elem = { trackElement.fromNodeId, oss.str () }; + rpElements.push_back (elem); + } + RecursiveIpv4RoutePathSearch (oss.str (), trackElement.destination, rpElements); + WriteRoutePath (trackElement.fromNodeId, trackElement.destination, rpElements); + } + +} + +void +AnimationInterface::TrackIpv4Route () +{ + if (Simulator::Now () > m_routingStopTime) + { + NS_LOG_INFO ("TrackIpv4Route completed"); + return; + } + if (m_routingNc.GetN ()) + { + for (NodeContainer::Iterator i = m_routingNc.Begin (); i != m_routingNc.End (); ++i) + { + Ptr n = *i; + if (!m_onlineMode) + WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n)); + else + WriteRouting (n->GetId (), GetIpv4RoutingTable (n)); + } + } + else + { + for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i) + { + Ptr n = *i; + if (!m_onlineMode) + WriteXmlRouting (n->GetId (), GetIpv4RoutingTable (n)); + else + WriteRouting (n->GetId (), GetIpv4RoutingTable (n)); + } + } + TrackIpv4RoutePaths (); + Simulator::Schedule (m_routingPollInterval, &AnimationInterface::TrackIpv4Route, this); +} + +std::string +AnimationInterface::GetIpv4RoutingTable (Ptr n) +{ + + NS_ASSERT (n); + Ptr ipv4 = n->GetObject (); + if (!ipv4) + { + NS_LOG_WARN ("Node " << n->GetId () << " Does not have an Ipv4 object"); + return ""; + } + std::stringstream stream; + Ptr routingstream = Create (&stream); + ipv4->GetRoutingProtocol ()->PrintRoutingTable (routingstream); + return stream.str (); + +} + +void +AnimationInterface::RecursiveIpv4RoutePathSearch (std::string from, std::string to, Ipv4RoutePathElements & rpElements) +{ + NS_LOG_INFO ("RecursiveIpv4RoutePathSearch from:" << from.c_str () << " to:" << to.c_str ()); + if ((from == "0.0.0.0") || (from == "127.0.0.1")) + { + NS_LOG_INFO ("Got " << from.c_str () << " End recursion"); + return; + } + Ptr fromNode = NodeList::GetNode (m_ipv4ToNodeIdMap[from]); + Ptr toNode = NodeList::GetNode (m_ipv4ToNodeIdMap[to]); + if (fromNode->GetId () == toNode->GetId ()) + { + Ipv4RoutePathElement elem = { fromNode->GetId (), "L" }; + rpElements.push_back (elem); + return; + } + if (!fromNode) + { + NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[from] << " Not found"); + return; + } + if (!toNode) + { + NS_FATAL_ERROR ("Node: " << m_ipv4ToNodeIdMap[to] << " Not found"); + return; + } + Ptr ipv4 = fromNode->GetObject (); + if (!ipv4) + { + NS_LOG_WARN ("ipv4 object not found"); + return; + } + Ptr rp = ipv4->GetRoutingProtocol (); + if (!rp) + { + NS_LOG_WARN ("Routing protocol object not found"); + return; + } + Ptr pkt = Create (); + Ipv4Header header; + header.SetDestination (Ipv4Address (to.c_str ())); + Socket::SocketErrno sockerr; + Ptr rt = rp->RouteOutput (pkt, header, 0, sockerr); + if (!rt) + { + return; + } + NS_LOG_DEBUG ("Node: " << fromNode->GetId () << " G:" << rt->GetGateway ()); + std::ostringstream oss; + oss << rt->GetGateway (); + if (oss.str () == "0.0.0.0" && (sockerr != Socket::ERROR_NOROUTETOHOST)) + { + NS_LOG_INFO ("Null gw"); + Ipv4RoutePathElement elem = { fromNode->GetId (), "C" }; + rpElements.push_back (elem); + if ( m_ipv4ToNodeIdMap.find (to) != m_ipv4ToNodeIdMap.end ()) + { + Ipv4RoutePathElement elem2 = { m_ipv4ToNodeIdMap[to], "L" }; + rpElements.push_back (elem2); + } + return; + } + NS_LOG_INFO ("Node:" << fromNode->GetId () << "-->" << rt->GetGateway ()); + Ipv4RoutePathElement elem = { fromNode->GetId (), oss.str () }; + rpElements.push_back (elem); + RecursiveIpv4RoutePathSearch (oss.str (), to, rpElements); + +} + + + +/***** WriteXml *****/ + +void +AnimationInterface::WriteXmlAnim (bool routing) +{ + AnimXmlElement element ("anim"); + element.AddAttribute ("ver", GetNetAnimVersion ()); + FILE * f = m_f; + if (!routing) + { + element.AddAttribute ("filetype", "animation"); + } + else + { + element.AddAttribute ("filetype", "routing"); + f = m_routingF; + } + WriteN (element.ToString (false) + ">\n", f); +} + +ParsedElement +AnimationInterface::WriteAnim (bool routing) +{ + ParsedElement parsedElement; + parsedElement.type = XML_ANIM; + parsedElement.version = QString(GetNetAnimVersion().c_str()).replace ("netanim-","").toDouble(); + /*if(m_animxmlparser){ + m_animxmlparser->doParse(parsedElement); + }*/ + return parsedElement; +} + +void +AnimationInterface::WriteXmlClose (std::string name, bool routing) +{ + std::string closeString = "\n"; + if (!routing) + { + WriteN (closeString, m_f); + } + else + { + WriteN (closeString, m_routingF); + } +} + +void +AnimationInterface::WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY) +{ + AnimXmlElement element ("node"); + element.AddAttribute ("id", id); + element.AddAttribute ("sysId", sysId); + element.AddAttribute ("locX", locX); + element.AddAttribute ("locY", locY); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteNode (uint32_t id, uint32_t sysId, double locX, double locY) +{ + ParsedElement parsedElement; + parsedElement.type = XML_NODE; + parsedElement.nodeId = id; + parsedElement.nodeSysId = sysId; + parsedElement.node_x = locX; + parsedElement.node_y = locY; + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription) +{ + AnimXmlElement element ("linkupdate"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("fromId", fromId); + element.AddAttribute ("toId", toId); + element.AddAttribute ("ld", linkDescription, true); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription) +{ + ParsedElement parsedElement; + parsedElement.type = XML_LINKUPDATE; + parsedElement.link_fromId = fromId; + parsedElement.link_toId = toId; + parsedElement.linkDescription = QString::fromStdString(linkDescription); + parsedElement.updateTime = Simulator::Now().GetSeconds();//.toString().toDouble (); + return parsedElement; +} + +void +AnimationInterface::WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId) +{ + AnimXmlElement element ("link"); + element.AddAttribute ("fromId", fromId); + element.AddAttribute ("toId", toId); + + LinkProperties lprop ; + lprop.fromNodeDescription = ""; + lprop.toNodeDescription = ""; + lprop.linkDescription = ""; + + P2pLinkNodeIdPair p1 = { fromId, toId }; + P2pLinkNodeIdPair p2 = { toId, fromId }; + if (m_linkProperties.find (p1) != m_linkProperties.end ()) + { + lprop = m_linkProperties[p1]; + } + else if (m_linkProperties.find (p2) != m_linkProperties.end ()) + { + lprop = m_linkProperties[p2]; + } + + element.AddAttribute ("fd", lprop.fromNodeDescription, true); + element.AddAttribute ("td", lprop.toNodeDescription, true); + element.AddAttribute ("ld", lprop.linkDescription, true); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteLink (uint32_t fromId, uint32_t toLp, uint32_t toId) +{ + ParsedElement parsedElement; + parsedElement.type = XML_LINK; + parsedElement.link_fromId = fromId; + parsedElement.link_toId = toId; + + LinkProperties lprop ; + lprop.fromNodeDescription = ""; + lprop.toNodeDescription = ""; + lprop.linkDescription = ""; + + P2pLinkNodeIdPair p1 = { fromId, toId }; + P2pLinkNodeIdPair p2 = { toId, fromId }; + if (m_linkProperties.find (p1) != m_linkProperties.end ()) + { + lprop = m_linkProperties[p1]; + } + else if (m_linkProperties.find (p2) != m_linkProperties.end ()) + { + lprop = m_linkProperties[p2]; + } + + parsedElement.fromNodeDescription = QString::fromStdString(lprop.fromNodeDescription); + parsedElement.toNodeDescription = QString::fromStdString(lprop.toNodeDescription); + parsedElement.linkDescription = QString::fromStdString(lprop.linkDescription); + return parsedElement; +} + +void +AnimationInterface::WriteXmlIpv4Addresses (uint32_t nodeId, std::vector ipv4Addresses) +{ + AnimXmlElement element ("ip"); + element.AddAttribute ("n", nodeId); + for (std::vector::const_iterator i = ipv4Addresses.begin (); + i != ipv4Addresses.end (); + ++i) + { + AnimXmlElement valueElement ("address"); + valueElement.SetText (*i); + element.AppendChild(valueElement); + } + WriteN (element.ToString (), m_f); +} + +void +AnimationInterface::WriteXmlIpv6Addresses (uint32_t nodeId, std::vector ipv6Addresses) +{ + AnimXmlElement element ("ipv6"); + element.AddAttribute("n", nodeId); + for (std::vector::const_iterator i = ipv6Addresses.begin (); + i != ipv6Addresses.end (); + ++i) + { + AnimXmlElement valueElement ("address"); + valueElement.SetText (*i); + element.AppendChild (valueElement); + } + WriteN(element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteIpv4Addresses (uint32_t nodeId, std::vector ipv4Addresses) +{ + ParsedElement parsedElement; + parsedElement.type = XML_IP; + parsedElement.nodeId = nodeId; + for (std::vector::const_iterator i = ipv4Addresses.begin (); + i != ipv4Addresses.end (); + ++i) + { + QString address = QString::fromStdString(*i); + parsedElement.ipAddresses.push_back(address); + } + return parsedElement; +} + +ParsedElement +AnimationInterface::WriteIpv6Addresses (uint32_t nodeId, std::vector ipv6Addresses) +{ + ParsedElement parsedElement; + parsedElement.type = XML_IP; + parsedElement.nodeId = nodeId; + for (std::vector::const_iterator i = ipv6Addresses.begin (); + i != ipv6Addresses.end (); + ++i) + { + QString address = QString::fromStdString(*i); + parsedElement.ipAddresses.push_back(address); + } + return parsedElement; +} + +void +AnimationInterface::WriteXmlRouting (uint32_t nodeId, std::string routingInfo) +{ + AnimXmlElement element ("rt"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + element.AddAttribute ("info", routingInfo.c_str (), true); + WriteN (element.ToString (), m_routingF); +} + +void +AnimationInterface::WriteRouting (uint32_t nodeId, std::string routingInfo) +{ + // AnimXmlElement element ("rt"); + // element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + // element.AddAttribute ("id", nodeId); + // element.AddAttribute ("info", routingInfo.c_str (), true); + // WriteN (element.ToString (), m_routingF); +} + +void +AnimationInterface::WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements) +{ + std::string tagName = "rp"; + AnimXmlElement element (tagName, false); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + element.AddAttribute ("d", destination.c_str ()); + element.AddAttribute ("c", rpElements.size ()); + for (Ipv4RoutePathElements::const_iterator i = rpElements.begin (); + i != rpElements.end (); + ++i) + { + Ipv4RoutePathElement rpElement = *i; + AnimXmlElement rpeElement ("rpe"); + rpeElement.AddAttribute ("n", rpElement.nodeId); + rpeElement.AddAttribute ("nH", rpElement.nextHop.c_str ()); + element.AppendChild (rpeElement); + } + WriteN (element.ToString (), m_routingF); +} + +void +AnimationInterface::WriteRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements) +{ + +} + +void +AnimationInterface::WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo) +{ + AnimXmlElement element ("pr"); + element.AddAttribute ("uId", animUid); + element.AddAttribute ("fId", fId); + element.AddAttribute ("fbTx", fbTx); + if (!metaInfo.empty ()) + { + element.AddAttribute ("meta-info", metaInfo.c_str (), true); + } + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WritePRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo) +{ + ParsedElement parsedElement; + parsedElement.type = ParsedElementType::XML_PACKET_TX_REF; + parsedElement.uid = animUid; + parsedElement.packetrx_fromId = fId; + parsedElement.packetrx_fbTx = fbTx; + + + if (!metaInfo.empty ()) + { + parsedElement.meta_info = QString::fromStdString(metaInfo); + } + if (parsedElement.meta_info == "") + { + parsedElement.meta_info = "null"; + } + return parsedElement; +} + +void +AnimationInterface::WriteXmlP (uint64_t animUid, std::string pktType, uint32_t tId, double fbRx, double lbRx) +{ + AnimXmlElement element (pktType); + element.AddAttribute ("uId", animUid); + element.AddAttribute ("tId", tId); + element.AddAttribute ("fbRx", fbRx); + element.AddAttribute ("lbRx", lbRx); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteP (uint64_t animUid, std::string pktType, uint32_t fId, double fbRx, double lbRx) +{ + ParsedElement parsedElement; + if(pktType == "pr"){ + parsedElement.isWpacket = false; + parsedElement.type = XML_PACKET_TX_REF; + parsedElement.packetrx_fromId = fId; + parsedElement.packetrx_fbRx = fbRx; + parsedElement.packetrx_lbRx = lbRx; + parsedElement.uid = animUid; + parsedElement.meta_info = "null"; + } + else if (pktType == "wpr"){ + parsedElement.isWpacket = true; + parsedElement.type = XML_WPACKET_RX_REF; + parsedElement.packetrx_fromId = fId; + parsedElement.packetrx_fbRx = fbRx; + parsedElement.packetrx_lbRx = lbRx; + parsedElement.uid = animUid; + parsedElement.meta_info = "null"; + } + return parsedElement; +} + +void +AnimationInterface::WriteXmlP(std::string pktType, uint32_t fId, double fbTx, double lbTx, + uint32_t tId, double fbRx, double lbRx, std::string metaInfo) +{ + AnimXmlElement element (pktType); + element.AddAttribute ("fId", fId); + element.AddAttribute ("fbTx", fbTx); + element.AddAttribute ("lbTx", lbTx); + if (!metaInfo.empty ()) + { + element.AddAttribute ("meta-info", metaInfo.c_str (), true); + } + element.AddAttribute ("tId", tId); + element.AddAttribute ("fbRx", fbRx); + element.AddAttribute ("lbRx", lbRx); + WriteN (element.ToString (), m_f); +} + + +ParsedElement +AnimationInterface::WriteP (std::string pktType, + uint32_t fId, + double fbTx, + double lbTx, + uint32_t tId, + double fbRx, + double lbRx, + std::string metaInfo) +{ + ParsedElement parsedElement; + if (pktType == "p"){ + parsedElement.isWpacket = false; + parsedElement.type = XML_PACKET_RX; + // parseGeneric (parsedElement); + parsedElement.packetrx_fromId = fId; + parsedElement.packetrx_fbTx = fbTx; + parsedElement.packetrx_lbTx = lbTx; + parsedElement.packetrx_toId = tId; + parsedElement.packetrx_fbRx = fbRx; + parsedElement.packetrx_lbRx = lbRx; + if (!parsedElement.packetrx_lbRx && parsedElement.packetrx_fbRx) + { + parsedElement.packetrx_lbRx = parsedElement.packetrx_fbRx; + } + parsedElement.meta_info = QString::fromStdString(metaInfo); + if (parsedElement.meta_info == "") + { + parsedElement.meta_info = "null"; + } + } + else if (pktType == "wp"){ + parsedElement.type = XML_WPACKET_RX; + parsedElement.isWpacket = true; + // parseGeneric (parsedElement); + parsedElement.packetrx_fromId = fId; + parsedElement.packetrx_fbTx = fbTx; + parsedElement.packetrx_lbTx = lbTx; + parsedElement.packetrx_toId = tId; + parsedElement.packetrx_fbRx = fbRx; + parsedElement.packetrx_lbRx = lbRx; + if (!parsedElement.packetrx_lbRx && parsedElement.packetrx_fbRx) + { + parsedElement.packetrx_lbRx = parsedElement.packetrx_fbRx; + } + parsedElement.meta_info = QString::fromStdString(metaInfo); + if (parsedElement.meta_info == "") + { + parsedElement.meta_info = "null"; + } + } + return parsedElement; +} + + +/*void +AnimationInterface::WriteXmlP(std::string pktType, uint32_t fId, double fbTx, double lbTx, + uint32_t tId, double fbRx, double lbRx, std::string metaInfo) +{ + AnimXmlElement element (pktType); + element.AddAttribute ("fId", fId); + element.AddAttribute ("fbTx", fbTx); + element.AddAttribute ("lbTx", lbTx); + if (!metaInfo.empty ()) + { + element.AddAttribute ("meta-info", metaInfo.c_str (), true); + } + element.AddAttribute ("tId", tId); + element.AddAttribute ("fbRx", fbRx); + element.AddAttribute ("lbRx", lbRx); + WriteN (element.ToString (), m_f); +}*/ +/* +ParsedElement +AnimationInterface::WriteP (std::string pktType, uint32_t fId, double fbTx, double lbTx, + uint32_t tId, double fbRx, double lbRx, std::string metaInfo) +{ + ParsedElement parsedElement; + parsedElement.isWpacket = false; + parsedElement.type = XML_PACKET_RX; + // parseGeneric (parsedElement); + return parsedElement; +}*/ + +void +AnimationInterface::WriteXmlAddNodeCounter (uint32_t nodeCounterId, std::string counterName, CounterType counterType) +{ + AnimXmlElement element ("ncs"); + element.AddAttribute ("ncId", nodeCounterId); + element.AddAttribute ("n", counterName); + element.AddAttribute ("t", CounterTypeToString (counterType)); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteAddNodeCounter (uint32_t counterId, std::string counterName, CounterType counterType){ + ParsedElement parsedElement; + parsedElement.type = XML_CREATE_NODE_COUNTER; + parsedElement.nodeCounterId = counterId; + parsedElement.nodeCounterName = QString::fromStdString(counterName); + QString Type = CounterTypeToString(counterType).c_str(); + if (Type == "UINT32") + parsedElement.nodeCounterType = ParsedElement::UINT32_COUNTER; + if (Type == "DOUBLE") + parsedElement.nodeCounterType = ParsedElement::DOUBLE_COUNTER; + return parsedElement; +} + +void +AnimationInterface::WriteXmlAddResource (uint32_t resourceId, std::string resourcePath) +{ + AnimXmlElement element ("res"); + element.AddAttribute ("rid", resourceId); + element.AddAttribute ("p", resourcePath); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteAddResource (uint32_t resourceId, std::string resourcePath) +{ + ParsedElement parsedElement; + parsedElement.type = XML_RESOURCE; + parsedElement.resourceId = resourceId; + parsedElement.resourcePath = QString::fromStdString(resourcePath); + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId) +{ + AnimXmlElement element ("nu"); + element.AddAttribute ("p", "i"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + element.AddAttribute ("rid", resourceId); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateNodeImage (uint32_t nodeId, uint32_t resourceId){ + ParsedElement parsedElement; + parsedElement.type = XML_NODEUPDATE; + parsedElement.nodeId = nodeId; + parsedElement.nodeUpdateType = ParsedElement::IMAGE; + parsedElement.updateTime = Simulator::Now ().GetSeconds ();//.toString ().toDouble (); + parsedElement.resourceId = resourceId; + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height) +{ + AnimXmlElement element ("nu"); + element.AddAttribute ("p", "s"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + element.AddAttribute ("w", width); + element.AddAttribute ("h", height); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateNodeSize (uint32_t nodeId, double width, double height) +{ + ParsedElement parsedElement; + parsedElement.type = XML_NODEUPDATE; + parsedElement.nodeId = nodeId; + parsedElement.nodeUpdateType = ParsedElement::SIZE; + parsedElement.updateTime = Simulator::Now ().GetSeconds ();//.toString ().toDouble (); + parsedElement.node_width = width; + parsedElement.node_height = height; + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y) +{ + AnimXmlElement element ("nu"); + element.AddAttribute ("p", "p"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + element.AddAttribute ("x", x); + element.AddAttribute ("y", y); + WriteN (element.ToString (), m_f); +} + + +ParsedElement +AnimationInterface::WriteUpdateNodePosition (uint32_t nodeId, double x, double y) +{ + ParsedElement parsedElement; + parsedElement.type = XML_NODEUPDATE; + parsedElement.updateTime = Simulator::Now ().GetSeconds ();//.toString ().toDouble (); + parsedElement.nodeId = nodeId; + parsedElement.nodeUpdateType = ParsedElement::POSITION; + parsedElement.node_x = x; + parsedElement.node_y = y; + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b) +{ + AnimXmlElement element ("nu"); + element.AddAttribute ("p", "c"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + element.AddAttribute ("r", (uint32_t) r); + element.AddAttribute ("g", (uint32_t) g); + element.AddAttribute ("b", (uint32_t) b); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b) +{ + ParsedElement parsedElement; + parsedElement.type = XML_NODEUPDATE; + parsedElement.nodeUpdateType = ParsedElement::COLOR; + parsedElement.updateTime = Simulator::Now ().GetSeconds ();//.toString ().toDouble (); + parsedElement.nodeId = nodeId; + parsedElement.node_r = (uint32_t) r; + parsedElement.node_g = (uint32_t) g; + parsedElement.node_b = (uint32_t) b; + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateNodeDescription (uint32_t nodeId) +{ + AnimXmlElement element ("nu"); + element.AddAttribute ("p", "d"); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("id", nodeId); + if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ()) + { + element.AddAttribute ("descr", m_nodeDescriptions[nodeId], true); + } + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateNodeDescription (uint32_t nodeId){ + ParsedElement parsedElement; + parsedElement.type = XML_NODEUPDATE; + parsedElement.updateTime = Simulator::Now ().GetSeconds ();//.toString ().toDouble (); + parsedElement.nodeId = nodeId; + parsedElement.nodeUpdateType = ParsedElement::DESCRIPTION; + if (m_nodeDescriptions.find (nodeId) != m_nodeDescriptions.end ()) + { + parsedElement.nodeDescription = QString::fromStdString(m_nodeDescriptions[nodeId]); + } + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateNodeCounter (uint32_t nodeCounterId, uint32_t nodeId, double counterValue) +{ + AnimXmlElement element ("nc"); + element.AddAttribute ("c", nodeCounterId); + element.AddAttribute ("i", nodeId); + element.AddAttribute ("t", Simulator::Now ().GetSeconds ()); + element.AddAttribute ("v", counterValue); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateNodeCounter (uint32_t counterId, uint32_t nodeId, double value) +{ + ParsedElement parsedElement; + parsedElement.type = XML_NODECOUNTER_UPDATE; + parsedElement.nodeCounterId = counterId; + parsedElement.nodeId = nodeId; + parsedElement.updateTime = Simulator::Now ().GetSeconds ();//.toString ().toDouble (); + parsedElement.nodeCounterValue = value; + return parsedElement; +} + +void +AnimationInterface::WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity) +{ + AnimXmlElement element ("bg"); + element.AddAttribute ("f", fileName); + element.AddAttribute ("x", x); + element.AddAttribute ("y", y); + element.AddAttribute ("sx", scaleX); + element.AddAttribute ("sy", scaleY); + element.AddAttribute ("o", opacity); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity){ + ParsedElement parsedElement; + parsedElement.type = XML_BACKGROUNDIMAGE; + parsedElement.fileName = QString::fromStdString(fileName); + parsedElement.x = x; + parsedElement.scaleX = scaleX; + parsedElement.scaleY = scaleY; + parsedElement.opacity = opacity; + return parsedElement; +} + +void +AnimationInterface::WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipAddress, std::string channelType) +{ + AnimXmlElement element ("nonp2plinkproperties"); + element.AddAttribute ("id", id); + element.AddAttribute ("ipAddress", ipAddress); + element.AddAttribute ("channelType", channelType); + WriteN (element.ToString (), m_f); +} + +ParsedElement +AnimationInterface::WriteNonP2pLinkProperties (uint32_t id, std::string ipAddress) +{ + ParsedElement parsedElement; + parsedElement.type = XML_NONP2P_LINK; + parsedElement.link_fromId = id; + parsedElement.fromNodeDescription = QString::fromStdString(ipAddress); + return parsedElement; +} + +/***** AnimXmlElement *****/ + +AnimationInterface::AnimXmlElement::AnimXmlElement(std::string tagName, bool emptyElement) : + m_tagName(tagName), + m_text("") +{ +} + +template +void +AnimationInterface::AnimXmlElement::AddAttribute(std::string attribute, T value, bool xmlEscape) +{ + std::ostringstream oss; + oss << std::setprecision(10); + oss << value; + std::string attributeString = attribute.c_str(); + if (xmlEscape) + { + attributeString += "=\""; + std::string valueStr = oss.str(); + for (std::string::iterator it = valueStr.begin(); it != valueStr.end(); ++it) + { + switch (*it) + { + case '&': + attributeString += "&"; + break; + case '\"': + attributeString += """; + break; + case '\'': + attributeString += "'"; + break; + case '<': + attributeString += "<"; + break; + case '>': + attributeString += ">"; + break; + default: + attributeString += *it; + break; + } + } + attributeString += "\" "; + } + else + { + attributeString += "=\"" + oss.str() + "\" "; + } + m_attributes.push_back(attributeString); +} + +void +AnimationInterface::AnimXmlElement::AppendChild(AnimXmlElement e) +{ + m_children.push_back(e.ToString()); +} + +void +AnimationInterface::AnimXmlElement::SetText(std::string text) +{ + m_text = text; +} + +std::string +AnimationInterface::AnimXmlElement::ToString(bool autoClose) +{ + std::string elementString = "<" + m_tagName + " "; + + + for (std::vector::const_iterator i = m_attributes.begin(); + i != m_attributes.end(); + ++i) + { + elementString += *i; + } + if (m_children.empty() && m_text.empty()) + { + if (autoClose) + { + elementString += "/>"; + } + } + else + { + elementString += ">"; + if (!m_text.empty()) + { + elementString += m_text; + } + if (!m_children.empty()) + { + elementString += "\n"; + for (std::vector::const_iterator i = m_children.begin(); + i != m_children.end(); + ++i) + { + elementString += *i + "\n"; + } + + } + if (autoClose) + { + elementString += ""; + } + } + + + return elementString + ((autoClose) ?"\n": ""); +} + + + + + +/***** AnimByteTag *****/ + +TypeId +AnimByteTag::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::AnimByteTag") + .SetParent () + .SetGroupName ("NetAnim") + .AddConstructor () + ; + return tid; +} + +TypeId +AnimByteTag::GetInstanceTypeId (void) const +{ + return GetTypeId (); +} + +uint32_t +AnimByteTag::GetSerializedSize (void) const +{ + return sizeof (uint64_t); +} + +void +AnimByteTag::Serialize (TagBuffer i) const +{ + i.WriteU64 (m_AnimUid); +} + +void +AnimByteTag::Deserialize (TagBuffer i) +{ + m_AnimUid = i.ReadU64 (); +} + +void +AnimByteTag::Print (std::ostream &os) const +{ + os << "AnimUid=" << m_AnimUid; +} + +void +AnimByteTag::Set (uint64_t AnimUid) +{ + m_AnimUid = AnimUid; +} + +uint64_t +AnimByteTag::Get (void) const +{ + return m_AnimUid; +} + +AnimationInterface::AnimPacketInfo::AnimPacketInfo () + : m_txnd (0), + m_txNodeId (0), + m_fbTx (0), + m_lbTx (0), + m_lbRx (0) +{ +} + +AnimationInterface::AnimPacketInfo::AnimPacketInfo (const AnimPacketInfo & pInfo) +{ + m_txnd = pInfo.m_txnd; + m_txNodeId = pInfo.m_txNodeId; + m_fbTx = pInfo.m_fbTx; + m_lbTx = pInfo.m_lbTx; + m_lbRx = pInfo.m_lbRx; +} + +AnimationInterface::AnimPacketInfo::AnimPacketInfo (Ptr txnd, + const Time fbTx, + uint32_t txNodeId) + : m_txnd (txnd), + m_txNodeId (0), + m_fbTx (fbTx.GetSeconds ()), + m_lbTx (0), + m_lbRx (0) +{ + if (!m_txnd) + m_txNodeId = txNodeId; +} + +void +AnimationInterface::AnimPacketInfo::ProcessRxBegin (Ptr nd, const double fbRx) +{ + Ptr n = nd->GetNode (); + m_fbRx = fbRx; + m_rxnd = nd; +} + +} // namespace ns3 \ No newline at end of file diff --git a/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.h b/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.h index b86a3a0..d8f1de0 100644 --- a/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.h +++ b/ns-3-allinone/ns-3-dev/src/netanim/model/animation-interface.h @@ -43,9 +43,33 @@ #include "ns3/rectangle.h" #include "ns3/ipv4.h" #include "ns3/ipv4-l3-protocol.h" - +#include "animxmlparser.h" +#include "netanim.h" +#include "animatormode.h" +#include "default-simulator-impl.h" namespace ns3 { +using netanim::ParsedElement; +using netanim::ParsedElementType; +using netanim::XML_INVALID; +using netanim::XML_ANIM; +using netanim::XML_TOPOLOGY; +using netanim::XML_NODE; +using netanim::XML_LINK; +using netanim::XML_NONP2P_LINK; +using netanim::XML_PACKET_RX; +using netanim::XML_WPACKET_RX; +using netanim::XML_LINKUPDATE; +using netanim::XML_NODEUPDATE; +using netanim::XML_RESOURCE; +using netanim::XML_BACKGROUNDIMAGE; +using netanim::XML_CREATE_NODE_COUNTER; +using netanim::XML_NODECOUNTER_UPDATE; +using netanim::XML_PACKET_TX_REF; +using netanim::XML_WPACKET_RX_REF; +using netanim::XML_IP; +using netanim::XML_IPV6; + #define MAX_PKTS_PER_TRACE_FILE 100000 #define PURGE_INTERVAL 5 #define NETANIM_VERSION "netanim-3.108" @@ -55,6 +79,8 @@ namespace ns3 { struct NodeSize; + + /** * \defgroup netanim Network Animation * @@ -71,15 +97,15 @@ struct NodeSize; */ class AnimationInterface { -public: +public: /** * \brief Constructor * \param filename The Filename for the trace file used by the Animator * */ + AnimationInterface(); AnimationInterface (const std::string filename); - /** * Counter Types */ @@ -422,6 +448,13 @@ class AnimationInterface */ double GetNodeEnergyFraction (Ptr node) const; +//getters for Online + + bool isOnlineMode(); + /*static AnimationInterface * GetNoXMLModeInstance (); + static netanim::NetAnim * GetNetAnim (); + static QApplication * GetQApplication ();*/ + private: /** @@ -634,6 +667,16 @@ class AnimationInterface static Rectangle * userBoundary; ///< user boundary bool m_trackPackets; ///< track packets +//##############New############## + bool m_onlineMode = false; + netanim::Animxmlparser * m_animxmlparser; + QApplication * m_application; + netanim::NetAnim * m_netanim; + + /*static AnimationInterface * noXMLNodeInstance; + static netanim::NetAnim * netAnim; + static QApplication * app; + netanim::Animxmlparser * m_parser*/ // Counter ID uint32_t m_remainingEnergyCounterId; ///< remaining energy counter ID @@ -1315,6 +1358,8 @@ class AnimationInterface * \param routing the routing */ void WriteXmlAnim (bool routing = false); + + ParsedElement WriteAnim (bool routing = false); /** * Write XML update node position function * \param nodeId the node ID @@ -1322,6 +1367,8 @@ class AnimationInterface * \param y the Y position */ void WriteXmlUpdateNodePosition (uint32_t nodeId, double x, double y); + + ParsedElement WriteUpdateNodePosition (uint32_t nodeId, double x, double y); /** * Write XML update node color function * \param nodeId the node ID @@ -1330,11 +1377,15 @@ class AnimationInterface * \param b the blue color */ void WriteXmlUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b); + + ParsedElement WriteUpdateNodeColor (uint32_t nodeId, uint8_t r, uint8_t g, uint8_t b); /** * Write XML update node description function * \param nodeId the node ID */ void WriteXmlUpdateNodeDescription (uint32_t nodeId); + + ParsedElement WriteUpdateNodeDescription (uint32_t nodeId); /** * Write XML update node size function * \param nodeId the node ID @@ -1342,12 +1393,16 @@ class AnimationInterface * \param height the height */ void WriteXmlUpdateNodeSize (uint32_t nodeId, double width, double height); + + ParsedElement WriteUpdateNodeSize (uint32_t nodeId, double width, double height); /** * Write XML add resource function * \param resourceId the resource ID * \param resourcePath the resource path */ void WriteXmlAddResource (uint32_t resourceId, std::string resourcePath); + + ParsedElement WriteAddResource (uint32_t resourceId, std::string resourcePath); /** * Write XML add node counter function * \param counterId the counter ID @@ -1355,12 +1410,16 @@ class AnimationInterface * \param counterType the counter type */ void WriteXmlAddNodeCounter (uint32_t counterId, std::string counterName, CounterType counterType); + + ParsedElement WriteAddNodeCounter (uint32_t counterId, std::string counterName, CounterType counterType); /** * Write XML update node image function * \param nodeId the node ID * \param resourceId the resource ID */ void WriteXmlUpdateNodeImage (uint32_t nodeId, uint32_t resourceId); + + ParsedElement WriteUpdateNodeImage (uint32_t nodeId, uint32_t resourceId); /** * Write XML update node counter function * \param counterId the counter ID @@ -1368,6 +1427,8 @@ class AnimationInterface * \param value the node counter value */ void WriteXmlUpdateNodeCounter (uint32_t counterId, uint32_t nodeId, double value); + + ParsedElement WriteUpdateNodeCounter (uint32_t counterId, uint32_t nodeId, double value); /** * Write XML node function * \param id the ID @@ -1376,6 +1437,8 @@ class AnimationInterface * \param locY the y location */ void WriteXmlNode (uint32_t id, uint32_t sysId, double locX, double locY); + + ParsedElement WriteNode (uint32_t id, uint32_t sysId, double locX, double locY); /** * Write XML link counter function * \param fromId the from device @@ -1383,6 +1446,8 @@ class AnimationInterface * \param toId the to ID */ void WriteXmlLink (uint32_t fromId, uint32_t toLp, uint32_t toId); + + ParsedElement WriteLink (uint32_t fromId, uint32_t toLp, uint32_t toId); /** * Write XML update link counter function * \param fromId the from device @@ -1390,6 +1455,8 @@ class AnimationInterface * \param linkDescription the link description */ void WriteXmlUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription); + + ParsedElement WriteUpdateLink (uint32_t fromId, uint32_t toId, std::string linkDescription); /** * Write XMLP function * \param pktType the packet type @@ -1409,6 +1476,15 @@ class AnimationInterface double fbRx, double lbRx, std::string metaInfo = ""); + + ParsedElement WriteP (std::string pktType, + uint32_t fId, + double fbTx, + double lbTx, + uint32_t tId, + double fbRx, + double lbRx, + std::string metaInfo = ""); /** * Write XMLP function * \param animUid the UID @@ -1418,6 +1494,8 @@ class AnimationInterface * \param lbTx the LB transmit */ void WriteXmlP (uint64_t animUid, std::string pktType, uint32_t fId, double fbTx, double lbTx); + + ParsedElement WriteP (uint64_t animUid, std::string pktType, uint32_t fId, double fbTx, double lbTx); /** * Write XMLP Ref function * \param animUid the UID @@ -1426,6 +1504,8 @@ class AnimationInterface * \param metaInfo the meta info */ void WriteXmlPRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo = ""); + + ParsedElement WritePRef (uint64_t animUid, uint32_t fId, double fbTx, std::string metaInfo = ""); /** * Write XML close function * \param name the name @@ -1439,12 +1519,16 @@ class AnimationInterface * \param channelType the channel type */ void WriteXmlNonP2pLinkProperties (uint32_t id, std::string ipAddress, std::string channelType); + + ParsedElement WriteNonP2pLinkProperties (uint32_t id, std::string ipAddress); /** * Write XML routing function * \param id the ID * \param routingInfo the routing info */ void WriteXmlRouting (uint32_t id, std::string routingInfo); + + void WriteRouting (uint32_t id, std::string routingInfo); /** * Write XMLRP function * \param nodeId the node ID @@ -1452,6 +1536,8 @@ class AnimationInterface * \param rpElements the route path elements */ void WriteXmlRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements); + + void WriteRp (uint32_t nodeId, std::string destination, Ipv4RoutePathElements rpElements); /** * Write XML update background function * \param fileName the file name @@ -1462,12 +1548,16 @@ class AnimationInterface * \param opacity the opacity */ void WriteXmlUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity); + + ParsedElement WriteUpdateBackground (std::string fileName, double x, double y, double scaleX, double scaleY, double opacity); /** * Write XML Ipv4 addresses function * \param nodeId the node ID * \param ipv4Addresses the list of Ipv4 addresses */ void WriteXmlIpv4Addresses (uint32_t nodeId, std::vector ipv4Addresses); + + ParsedElement WriteIpv4Addresses (uint32_t nodeId, std::vector ipv4Addresses); /** * Write XML Ipv6 addresses function * \param nodeId the node ID @@ -1475,11 +1565,14 @@ class AnimationInterface */ void WriteXmlIpv6Addresses (uint32_t nodeId, std::vector ipv6Addresses); + ParsedElement WriteIpv6Addresses (uint32_t nodeId, std::vector ipv4Addresses); + }; + /** * \ingroup netanim * diff --git a/ns-3-allinone/ns-3-dev/src/netanim/wscript b/ns-3-allinone/ns-3-dev/src/netanim/wscript index 7be7b6a..e946d39 100644 --- a/ns-3-allinone/ns-3-dev/src/netanim/wscript +++ b/ns-3-allinone/ns-3-dev/src/netanim/wscript @@ -7,8 +7,11 @@ NETANIM_RELEASE_NAME = "netanim-3.108" def build (bld) : module = bld.create_ns3_module ('netanim', ['internet', 'mobility', 'wimax', 'wifi', 'csma', 'lte', 'uan', 'lr-wpan', 'energy', 'wave']) - module.includes = '.' + #module.includes = '.' module.source = [ 'model/animation-interface.cc', ] + module.includes = ['.', '../../../netanim/', '/usr/include/qt4', '/usr/include/qt4/QtGui', '/usr/include/qt4/QtCore'] + module.lib = ['NetAnimOnline', 'QtGui', 'QtCore'] + module.linkflags = ['-lNetAnimOnline', '-L../../netanim/', '-Wl,-R,../../netanim/'] netanim_test = bld.create_ns3_module_test_library('netanim') netanim_test.source = ['test/netanim-test.cc', ] headers = bld(features='ns3header') diff --git a/ns-3-allinone/ns-3-dev/wscript b/ns-3-allinone/ns-3-dev/wscript index 3452ee8..7c7d1ac 100644 --- a/ns-3-allinone/ns-3-dev/wscript +++ b/ns-3-allinone/ns-3-dev/wscript @@ -767,6 +767,9 @@ def add_scratch_programs(bld): obj.target = name obj.name = obj.target obj.install_path = None + obj.lib = ['NetAnimOnline', 'QtGui', 'QtCore'] + obj.includes += " ".join(['.', '../../netanim', '/usr/include/qt4/QtCore', '/usr/include/qt4/QtGui', '/usr/include/qt4' ]) + obj.linkflags = ['-lNetAnimOnline', '-L../../netanim', '-Wl,-R,../netanim'] except OSError: return