Skip to content
This repository has been archived by the owner on Apr 10, 2020. It is now read-only.

Commit

Permalink
[*] Partial support of ASA and JunOS emulation (GUI part to complete)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Grossmann committed Jun 25, 2009
1 parent e796564 commit 24ccb17
Show file tree
Hide file tree
Showing 17 changed files with 426 additions and 288 deletions.
6 changes: 3 additions & 3 deletions GNS3.e4p
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-4.6.dtd">
<!-- eric4 project file for project GNS3 -->
<!-- Saved: 2009-05-22, 13:11:34 -->
<!-- Saved: 2009-06-19, 00:35:49 -->
<!-- Copyright (C) 2009 , -->
<Project version="4.6">
<Language>en</Language>
Expand Down Expand Up @@ -104,13 +104,11 @@
<Source>src/GNS3/Ui/ConfigurationPages/Page_ATMBR.py</Source>
<Source>src/GNS3/Ui/ConfigurationPages/Form_ATMBRPage.py</Source>
<Source>src/GNS3/Node/ATMBR.py</Source>
<Source>src/GNS3/Node/FW.py</Source>
<Source>src/GNS3/Ui/ConfigurationPages/Form_FWPage.py</Source>
<Source>src/GNS3/Ui/ConfigurationPages/Page_FW.py</Source>
<Source>src/GNS3/PemuManager.py</Source>
<Source>src/GNS3/Ui/ConfigurationPages/Page_PreferencesPemu.py</Source>
<Source>src/GNS3/Ui/ConfigurationPages/Form_PreferencesPemu.py</Source>
<Source>src/GNS3/Defaults/FWDefaults.py</Source>
<Source>src/GNS3/Defaults/IOSRouterDefaults.py</Source>
<Source>gns3</Source>
<Source>src/GNS3/Ui/ConfigurationPages/Page_DecorativeNode.py</Source>
Expand All @@ -134,6 +132,8 @@
<Source>src/GNS3/Unpack/setup.py</Source>
<Source>src/GNS3/Unpack/README.txt</Source>
<Source>src/GNS3/UndoFramework.py</Source>
<Source>src/GNS3/Node/AnyEmuDevice.py</Source>
<Source>src/GNS3/Defaults/AnyEmuDefaults.py</Source>
</Sources>
<Forms>
<Form>src/GNS3/Ui/Form_NodeConfigurator.ui</Form>
Expand Down
2 changes: 1 addition & 1 deletion pemu/pemuwrapper.py
Expand Up @@ -48,7 +48,7 @@


__author__ = 'Thomas Pani'
__version__ = '0.2.3' # TODO: remove RC when done
__version__ = '0.2.3'

PORT = 10525
PEMU_INSTANCES = {}
Expand Down
5 changes: 3 additions & 2 deletions src/GNS3/Console.py
Expand Up @@ -273,8 +273,9 @@ def do_idlepc(self, args):
if command == 'get' or command == 'show':
device = params[0]
if command == 'get':
if self.dynagen.devices[device].idlepc != None:
print unicode(translate("Console", "%s already has an idlepc value applied.")) % device
current_idlepc = self.dynagen.devices[device].idlepc
if len(params) < 2 or params[1] != 'force' and current_idlepc != None:
print unicode(translate("Console", "%s already has an idlepc value applied (%s).")) % (device, current_idlepc)
return

print translate("Console", "Please wait while gathering statistics...")
Expand Down
3 changes: 2 additions & 1 deletion src/GNS3/Defaults/AbstractDefaults.py
Expand Up @@ -25,11 +25,12 @@
class AbstractDefaults(object):
""" Abstract class for managing the device defaults """

model = None

def __init__(self):

self.dynagen = globals.GApp.dynagen
self.config = None
self.model = None

def set_int_option(self, option, argument):
""" Set integer type option in config
Expand Down
Expand Up @@ -23,16 +23,14 @@
import GNS3.Globals as globals
from GNS3.Defaults.AbstractDefaults import AbstractDefaults

class FWDefaults(AbstractDefaults):
class AnyEmuDefaults(AbstractDefaults):
"""Abstract class for managing the FW defaults"""

def __init__(self):

AbstractDefaults.__init__(self)

self.default_image = 'None'
self.default_serial = '0x12345678'
self.default_key = '0x00000000,0x00000000,0x00000000,0x00000000'
self.default_ram = 128
self.pemu = None
self.d = None
Expand Down Expand Up @@ -64,3 +62,15 @@ def set_image(self, image, model):
del self.config['image']
else:
self.config['image'] = image

class FWDefaults(AnyEmuDefaults):
def __init__(self):
AnyEmuDefaults.__init__(self)
self.default_serial = '0x12345678'
self.default_key = '0x00000000,0x00000000,0x00000000,0x00000000'

class ASADefaults(AnyEmuDefaults):
pass

class OliveDefaults(AnyEmuDefaults):
pass
6 changes: 3 additions & 3 deletions src/GNS3/Dynagen/console.py
Expand Up @@ -455,8 +455,8 @@ def show_device(self, params):
if len(params) == 1: #if this is only 'show device' command print info about all devices
output = []
for device in self.dynagen.devices.values():
#if it is a router or FW
if isinstance(device, self.namespace.Router) or isinstance(device, self.namespace.FW) or isinstance(device, self.namespace.FRSW) or isinstance(device, self.namespace.ATMBR) or isinstance(device, self.namespace.ATMSW) or isinstance(device, self.namespace.ETHSW):
#if it is a router or other emulated device
if isinstance(device, (self.namespace.Router, self.namespace.AnyEmuDev, self.namespace.FRSW, self.namespace.ATMBR, self.namespace.ATMSW, self.namespace.ETHSW)):
output.append(device.info())
output.sort()
for devinfo in output:
Expand All @@ -465,7 +465,7 @@ def show_device(self, params):
#if this is 'show device {something}' command print info about specific device
try:
device = self.dynagen.devices[params[1]]
if isinstance(device, self.namespace.Router) or isinstance(device, self.namespace.FW) or isinstance(device, self.namespace.FRSW) or isinstance(device, self.namespace.ATMBR) or isinstance(device, self.namespace.ATMSW) or isinstance(device, self.namespace.ETHSW):
if isinstance(device, (self.namespace.Router, self.namespace.AnyEmuDev, self.namespace.FRSW, self.namespace.ATMBR, self.namespace.ATMSW, self.namespace.ETHSW)):
print device.info()
except KeyError:
error('unknown device: ' + params[1])
Expand Down
75 changes: 38 additions & 37 deletions src/GNS3/Dynagen/dynagen.py
Expand Up @@ -34,7 +34,7 @@
CISCO2600_MB_1E, CISCO2600_MB_2E, CISCO2600_MB_1FE, CISCO2600_MB_2FE, PA_2FE_TX, \
PA_GE, PA_C7200_IO_2FE, PA_C7200_IO_GE_E, C1700, CISCO1710_MB_1FE_1E, C1700_MB_1ETH, \
DEVICETUPLE, DynamipsVerError, DynamipsErrorHandled, NM_CIDS, NM_NAM, get_reverse_udp_nio
from pemu_lib import Pemu, FW, nosend_pemu
from pemu_lib import Pemu, AnyEmuHandler, FW, ASA, Olive, nosend_pemu
from validate import Validator
from configobj import ConfigObj, flatten_errors
from optparse import OptionParser
Expand All @@ -53,10 +53,14 @@
C3745,
C3600,
C7200,
ASA,
FW,
Olive,
)
DEVICETUPLE = ( # A tuple of known device names
'525',
'5520',
'O-series',
'1710',
'1720',
'1721',
Expand Down Expand Up @@ -182,13 +186,6 @@ def __init__(self):
'cnfg',
]

self.generic_fw_options = [
'image',
'ram',
'key',
'serial',
]

self.defaults_config_ran = False
self.default_workingdir = ''

Expand Down Expand Up @@ -364,8 +361,8 @@ def disconnect(self, local_device, source, dest, automatically_remove_unused_slo
slot2 = int(slot2)
port2 = int(port2)

#TODO add removal for FW
if isinstance(remote_device, FW):
#TODO add removal for emulated devices
if isinstance(remote_device, AnyEmuHandler):
raise DynamipsError, 'pemuwrapper does not support removal'
#disconnect local from remote
local_device.slot[slot1].disconnect(pa1, port1)
Expand Down Expand Up @@ -535,17 +532,17 @@ def connect(self, local_device, source, dest):
self.smartslot(remote_device, pa2, slot2, port2)

#perform the connection
if isinstance(local_device, FW) and isinstance(remote_device, Router):
if isinstance(local_device, AnyEmuHandler) and isinstance(remote_device, Router):
local_device.connect_to_dynamips(
port1,
remote_device.dynamips,
remote_device.slot[slot2],
pa2,
port2,
)
elif isinstance(local_device, FW) and isinstance(remote_device, FW):
local_device.connect_to_fw(port1, remote_device, port2)
elif isinstance(local_device, Router) and isinstance(remote_device, FW):
elif isinstance(local_device, AnyEmuHandler) and isinstance(remote_device, AnyEmuHandler):
local_device.connect_to_emulated_device(port1, remote_device, port2)
elif isinstance(local_device, Router) and isinstance(remote_device, AnyEmuHandler):
remote_device.connect_to_dynamips(
port2,
local_device.dynamips,
Expand Down Expand Up @@ -574,7 +571,7 @@ def connect(self, local_device, source, dest):
# If this LAN doesn't already exist, create it
self.bridges[interface] = Bridge(local_device.dynamips, name=interface)
#perform the connection
if isinstance(local_device, FW):
if isinstance(local_device, AnyEmuHandler):
local_device.connect_to_dynamips(
port1,
self.bridges[interface].dynamips,
Expand Down Expand Up @@ -615,7 +612,7 @@ def connect(self, local_device, source, dest):
else:
return False

if isinstance(local_device, FW):
if isinstance(local_device, AnyEmuHandler):
local_device.connect_to_dynamips(
port1,
remote_device.dynamips,
Expand Down Expand Up @@ -657,13 +654,13 @@ def smartslot(
else:
pa = pa[0].lower()

if isinstance(router, FW):
if isinstance(router, AnyEmuHandler):
#TODO, apparently there is only support in pemu for e0-4. Talked to mmm123 about this, he is aware of that, but does not consider this a showstopper
if pa == 'e' and port >= 0 and port < 5:
router.add_interface(pa, port)
return
else:
raise DynamipsError, 'FW on pemuwrapper only supports e0-4'
raise DynamipsError, 'Emulated device on pemuwrapper only supports e0-4'

try:
if router.slot[slot] != None:
Expand Down Expand Up @@ -1055,15 +1052,15 @@ def import_config(self, FILENAME):
for key in DEVICETUPLE:
devdefaults[key] = {}

#handle the FW
#handle the emulated devices
for subsection in server.sections:
device = server[subsection]

if device.name in ['525']:
if device.name in ['525', '5520', 'O-series']:
# Populate the appropriate dictionary
for scalar in device.scalars:
if device[scalar] != None:
devdefaults['525'][scalar] = device[scalar]
devdefaults[device.name][scalar] = device[scalar]
continue

# Create the device
Expand All @@ -1076,23 +1073,27 @@ def import_config(self, FILENAME):

if devtype.lower() == 'fw':
dev = FW(self.dynamips[pemu_name], name=name)
elif devtype.lower() == 'asa':
dev = ASA(self.dynamips[pemu_name], name=name)
elif devtype.lower() == 'olive':
dev = Olive(self.dynamips[pemu_name], name=name)
else:
self.dowarning('Unable to identify the type of device ' + device.name)
self.import_error = True
continue

#set the defaults
for option in devdefaults['525']:
for option in devdefaults[dev.model_string]:
if option in (
'console',
'key',
'serial',
'ram',
'image',
):
setattr(dev, option, devdefaults['525'][option])
setattr(dev, option, devdefaults[dev.model_string][option])

#add the whole FW into global dictionary
#add the whole device into global dictionary
self.devices[name] = dev

#set the special device options
Expand All @@ -1119,7 +1120,7 @@ def import_config(self, FILENAME):
self.dowarning( 'ignoring unknown config item: %s = %s' % (str(subitem), str(device[subitem])))
self.import_error = True

# Set default autostart flag for this fw if not already set
# Set default autostart flag for this emulated device if not already set
if device['autostart'] == None:
self.autostart[name] = config['autostart']
else:
Expand Down Expand Up @@ -1715,17 +1716,17 @@ def get_defaults_config(self):
for device in self.devices.values():
#skip non-routers
if isinstance(device, FRSW) or isinstance(device, ATMSW) or isinstance(device, ETHSW) or isinstance(device, ATMBR):
#TODO FW, FRSW, ATMSW, ETHSW support
#TODO FRSW, ATMSW, ATMBR, ETHSW support
continue
if device.dynamips == hypervisor:
if isinstance(device, FW):
if isinstance(device, AnyEmuHandler):
model = device.model_string
self.defaults_config[h][model] = {}
if device.image == None:
self.error('specify at least image file for device ' + device.name)
device.image = '"None"'
self.defaults_config[h][model]['image'] = device.image
for option in self.generic_fw_options:
for option in device.available_options:
if getattr(device, option) != device.defaults[option]:
self.defaults_config[h][model][option] = getattr(device, option)
else:
Expand Down Expand Up @@ -1928,26 +1929,26 @@ def _update_running_config_for_ethsw(self, hypervisor, ethsw):
else:
self.running_config[h][e][str(port1)] = porttype + ' ' + str(vlan) + ' ' + nio.config_info()

def _update_running_config_for_fw(self, hypervisor, device, need_active_config):
"""parse the all data structures associated with this fw and update the running_config properly"""
def _update_running_config_for_emulated_device(self, hypervisor, device, need_active_config):
"""parse the all data structures associated with this emulated device and update the running_config properly"""

h = 'pemu ' + hypervisor.host
f = 'FW ' + device.name
f = '%s %s' % (device.basehostname, device.name)
self.running_config[h][f] = {}

#find out the model of the router
model = device.model_string

#populate with non-default router information
defaults = self.defaults_config[h][model]
for option in self.generic_fw_options:
for option in device.available_options:
self._set_option_in_config(self.running_config[h][f], defaults, device, option)

for port in device.nios:
if device.nios[port] != None:
con = 'e' + str(port)
(remote_router, remote_adapter, remote_port) = get_reverse_udp_nio(device.nios[port])
if isinstance(remote_router, FW):
if isinstance(remote_router, AnyEmuHandler):
self.running_config[h][f][con] = remote_router.name + ' ' + remote_adapter + str(remote_port)
elif isinstance(remote_router, Router):
self.running_config[h][f][con] = self._translate_interface_connection(remote_adapter, remote_router, remote_port)
Expand Down Expand Up @@ -2036,8 +2037,8 @@ def update_running_config(self, need_active_config=False):
elif isinstance(device, Router):
#for routers - create the router running config by going throught all variables in dynamips_lib
self._update_running_config_for_router(hypervisor, device, need_active_config)
elif isinstance(device, FW):
self._update_running_config_for_fw(hypervisor, device, need_active_config)
elif isinstance(device, AnyEmuHandler):
self._update_running_config_for_emulated_device(hypervisor, device, need_active_config)

#after everything is done merge this config with defaults_config
temp_config = ConfigObj(self.defaults_config, encoding='utf-8')
Expand Down Expand Up @@ -2067,8 +2068,8 @@ def get_running_config(self, params):
if isinstance(device, Router):
device_section = self.running_config[hypervisor_name]['ROUTER ' + device.name]
print '\t' + '[[ROUTER ' + device.name + ']]'
if isinstance(device, FW):
device_section = self.running_config[hypervisor_name]['FW ' + device.name]
if isinstance(device, AnyEmuHandler):
device_section = self.running_config[hypervisor_name]['%s %s' % (device.basehostname, device.name)]
print '\t' + '[[ROUTER ' + device.name + ']]'
elif isinstance(device, FRSW):
device_section = self.running_config[hypervisor_name]['FRSW ' + device.name]
Expand Down

0 comments on commit 24ccb17

Please sign in to comment.