imalse / scenario / ddos_flooding / server_cmd.py

"""

This file contains the Server Command Meta Description for the ddos ping
flooding scenario.

"""
import copy

import jsonpickle

from core.nodes.server import ServerCMD as SCMD
from scenario.ddos_flooding.config import ServerDescription as Description
from scenario.ddos_flooding.config import HttpGetFloodCmd
class ServerCMD(SCMD):
    
    """This class is a subclass of ServerCMD."""
    
    def __init__(self, desc=None):        
        """Initialize"""
        
        if desc == None:
            desc = Description()
        
        SCMD.__init__(self, desc)
    
    def forward_to_bots(self, sock, command):
        """Forward data to all the bots"""        
        
        # If we are in simulation mode, the webservice will be started         
        if self.node.NODE_TYPE != 'real' and isinstance(command, HttpGetFloodCmd):
            print "starting webservice"
            self.node.start_webservice()
        
        self.logger.info('start to echo_bots' )
        new_data = copy.deepcopy(command)
        new_data.event = command.bot_event
        del new_data.bot_event
        
        for client_sock in self.node.client_socks:            
            self.node.send(client_sock, jsonpickle.encode(new_data))
        
        
        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.