import os import re import time import json import requests from multiprocessing import Process from multiprocessing import Queue from pexpect import pxssh import functest.utils.functest_logger as ft_logger OK = 200 CREATED = 201 ACCEPTED = 202 NO_CONTENT = 204 class Sfc_fun: """Defines all the def function of SFC.""" def __init__(self): """Initialization of variables.""" self.logger = ft_logger.Logger("sfc_fun").getLogger() self.osver = "v2.0" self.token_id = 0 self.net_id = 0 self.image_id = 0 self.keystone_hostname = 'keystone_ip' self.neutron_hostname = 'neutron_ip' self.nova_hostname = 'nova_ip' self.glance_hostname = 'glance_ip' self.onos_hostname = 'onos_ip' # Network variables ####### self.netname = "test_nw" self.admin_state_up = True self.tenant_id = 0 self.subnetId = 0 # ######################### # SubNet variables######### self.ip_version = 4 self.cidr = "20.20.20.0/24" self.subnetname = "test_nw_subnets" # ############################### # Port variable self.port = "port" self.port_num = [] self.vm_id = 0 self.port_ip = [] self.count = 0 self.i = 0 self.numTerms = 3 self.security_groups = [] self.port_security_enabled = False # ############################### # VM creation variable self.container_format = "bare" self.disk_format = "qcow2" self.imagename = "TestSfcVm" self.createImage = "/home/root1/devstack/files/images/\ firewall_block_image.img" self.vm_name = "vm" self.imageRef = "test" self.flavorRef = "1" self.max_count = "1" self.min_count = "1" self.org_nw_port = [] self.image_id = 0 self.routername = "router1" self.router_id = 0 # ##################################### # Port pair self.port_pair_ingress = 0 self.port_pair_egress = 0 self.port_pair_name = "PP" self.port_pair_id = [] # #################################### # Port Group self.port_group_name = "PG" self.port_grp_id = [] # #################################### # FlowClassifier self.source_ip_prefix = "20.20.20.0/24" self.destination_ip_prefix = "20.20.20.0/24" self.logical_source_port = 0 self.fcname = "FC" self.ethertype = "IPv4" # ##################################### self.flow_class_if = 0 # ##################################### # Port Chain variables self.pcname = 'PC' self.PC_id = 0 # ##################################### # Port Chain variables self.flowadd = '' # ##################################### self.ip_pool = 0 self.vm_public_ip = [] self.vm_public_id = [] self.net_id1 = 0 self.vm = [] self.address = 0 self.value = 0 self.pub_net_id = 0 def getToken(self): """Get the keystone token value from Openstack .""" url = 'http://' + self.keystone_hostname + \ ':5000/' + self.osver + '/tokens' data = '{"auth": {"tenantName": "admin", "passwordCredentials":\ { "username": "admin", "password": "console"}}}' headers = {"Accept": "application/json"} response = requests.post(url, headers=headers, data=data) if (response.status_code == OK): json1_data = json.loads(response.content) self.logger.debug(response.status_code) self.logger.debug(response.content) self.logger.debug(json1_data) self.token_id = json1_data['access']['token']['id'] self.tenant_id = json1_data['access']['token']['tenant']['id'] return(response.status_code) else: return(response.status_code) def createNetworks(self): """Creation of networks.""" Dicdata = {} if self.netname != '': Dicdata['name'] = self.netname if self.admin_state_up != '': Dicdata['admin_state_up'] = self.admin_state_up Dicdata = {'network': Dicdata} data = json.dumps(Dicdata, indent=4) url = 'http://' + self.neutron_hostname + \ ':9696/' + self.osver + '/networks' headers = {"Accept": "application/json", "X-Auth-Token": self.token_id} response = requests.post(url, headers=headers, data=data) if (response.status_code == CREATED): self.logger.debug(response.status_code) self.logger.debug(response.content) json1_data = json.loads(response.content) self.logger.debug(json1_data) self.net_id = json1_data['network']['id'] return(response.status_code) else: return(response.status_code) def createSubnets(self): """Creation of SubNets.""" Dicdata = {} if self.net_id != 0: Dicdata['network_id'] = self.net_id if self.ip_version != '': Dicdata['ip_version'] = self.ip_version if self.cidr != '': Dicdata['cidr'] = self.cidr if self.subnetname != '': Dicdata['name'] = self.subnetname Dicdata = {'subnet': Dicdata} data = json.dumps(Dicdata, indent=4) url = 'http://' + self.neutron_hostname + \ ':9696/' + self.osver + '/subnets' headers = {"Accept": "application/json", "X-Auth-Token": self.token_id} response = requests.post(url, headers=headers, data=data) if (response.status_code == CREATED): self.logger.debug(response.status_code) self.logger.debug(response.content) json1_data = json.loads(response.content) self.logger.debug(json1_data) self.subnetId = json1_data['subnet']['id'] return(response.status_code) else: return(response.status_code) def createPorts(self): """Creation of Ports.""" for x in range(self.i, self.numTerms): Dicdata = {} if self.net_id != '': Dicdata['network_id'] = self.net_id if self.port != '': Dicdata['name'] = "port" + str(x) if self.admin_state_up != '': Dicdata['admin_state_up'] = self.admin_state_up if self.security_groups != '': Dicdata['security_groups'] = self.security_groups # if self.port_security_enabled != '': # Dicdata['port_security_enabled'] = self.port_security_enabled Dicdata = {'port': Dicdata} data = json.dumps(Dicdata, indent=4) url = 'http://' + self.neutron_hostname + \ ':9696/' + self.osver + '/ports' headers = {"Accept": "application/json", "X-Auth-Token": self.token_id} response = requests.post(url, headers=headers, data=data) if (response.status_code == CREATED): self.logger.debug(response.status_code) self.logger.debug(response.content) json1_data = json.loads(response.content) self.logger.debug(json1_data) self.port_num.append(json1_data['port']['id']) self.port_ip.append(json1_data['port']['fixed_ips'][0] ['ip_address']) else: return(response.status_code) return(response.status_code) def createVm(self): """Creation of Instance, using firewall image.""" url = 'http://' + self.glance_hostname + \ ':9292/v2/images?name=TestSfcVm' headers = {"Accept": "application/json", "Content-Type": "application/\ octet-stream", "X-Auth-Token": self.token_id} response = requests.get(url, headers=headers) if (response.status_code == OK): self.logger.debug(response.status_code) self.logger.debug(response.content) self.logger.info("FireWall Image is available") json1_data = json.loads(response.content) self.logger.debug(json1_data) self.image_id = json1_data['images'][0]['id'] else: return(response.status_code) url = 'http://' + self.nova_hostname + \ ':8774/v2.1/' + self.tenant_id + '/flavors?name=m1.tiny' headers = {"Accept": "application/json", "Content-Type": "application/json", "X-Auth-Token": self.token_id} response = requests.get(url, headers=headers) if (response.status_code == OK): self.logger.debug(response.status_code) self.logger.debug(response.content) self.logger.info("Flavor is available") json1_data = json.loads(response.content) self.logger.debug(json1_data) self.flavorRef = json1_data['flavors'][0]['id'] else: return(response.status_code) for y in range(0, 3): Dicdata = {} org_nw_port = [] org_nw_port.append({'port': self.port_num[y]}) if self.vm_name != '': Dicdata['name'] = "vm" + str(y) if self.imageRef != '': Dicdata['imageRef'] = self.image_id if self.flavorRef != '': Dicdata['flavorRef'] = self.flavorRef if self.max_count != '': Dicdata['max_count'] = self.max_count if self.min_count != '': Dicdata['min_count'] = self.min_count if self.org_nw_port != '': Dicdata['networks'] = org_nw_port
/* linux/arch/arm/mach-s3c2410/pm.c
*
* Copyright (c) 2006 Simtec Electronics
* Ben Dooks <ben@simtec.co.uk>
*
* S3C2410 (and compatible) Power Manager (Suspend-To-RAM) support
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 <linux/init.h>
#include <linux/suspend.h>
#include <linux/errno.h>
#include <linux/time.h>
#include <linux/device.h>
#include <linux/syscore_ops.h>
#include <linux/gpio.h>
#include <linux/io.h>
#include <asm/mach-types.h>
#include <mach/hardware.h>
#include <mach/regs-gpio.h>
#include <mach/gpio-samsung.h>
#include <plat/gpio-cfg.h>
#include <plat/cpu.h>
#include <plat/pm.h>
#include "h1940.h"
static void s3c2410_pm_prepare(void)
{
/* ensure at least GSTATUS3 has the resume address */
__raw_writel(virt_to_phys(s3c_cpu_resume), S3C2410_GSTATUS3);
S3C_PMDBG("GSTATUS3 0x%08x\n", __raw_readl(S3C2410_GSTATUS3));
S3C_PMDBG("GSTATUS4 0x%08x\n", __raw_readl(S3C2410_GSTATUS4));
if (machine_is_h1940()) {
void *base = phys_to_virt(H1940_SUSPEND_CHECK);
unsigned long ptr;
unsigned long calc = 0;
/* generate check for the bootloader to check on resume */
for (ptr = 0; ptr < 0x40000; ptr += 0x400)
calc += __raw_readl(base+ptr);
__raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
}
/* RX3715 and RX1950 use similar to H1940 code and the
* same offsets for resume and checksum pointers */
if (machine_is_rx3715() || machine_is_rx1950()) {
void *base = phys_to_virt(H1940_SUSPEND_CHECK);
unsigned long ptr;
unsigned long calc = 0;
/* generate check for the bootloader to check on resume */
for (ptr = 0; ptr < 0x40000; ptr += 0x4)
calc += __raw_readl(base+ptr);
__raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
}
if (machine_is_aml_m5900()) {
gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_HIGH, NULL);
gpio_free(S3C2410_GPF(2));
}
if (machine_is_rx1950()) {
/* According to S3C2442 user's manual, page 7-17,
* when the system is operating in NAND boot mode,
* the hardware pin configuration - EINT[23:21] –
* must be set as input for starting up after
* wakeup from sleep mode
*/
s3c_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_INPUT);
s3c_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPIO_INPUT);
s3c_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPIO_INPUT);
}
}
static void s3c2410_pm_resume(void)
{
unsigned long tmp;
/* unset the return-from-sleep flag, to ensure reset */
tmp = __raw_readl(S3C2410_GSTATUS2);
tmp &= S3C2410_GSTATUS2_OFFRESET;
__raw_writel(tmp, S3C2410_GSTATUS2);
if (machine_is_aml_m5900()) {
gpio_request_one(S3C2410_GPF(2), GPIOF_OUT_INIT_LOW, NULL);
gpio_free(S3C2410_GPF(2));
}
}
struct syscore_ops s3c2410_pm_syscore_ops = {
.resume = s3c2410_pm_resume,
};
static int s3c2410_pm_add(struct device *dev, struct subsys_interface *sif)
{
pm_cpu_prep = s3c2410_pm_prepare;
pm_cpu_sleep = s3c2410_cpu_suspend;
return 0;
}
#if defined(CONFIG_CPU_S3C2410)
static struct subsys_interface s3c2410_pm_interface = {
.name = "s3c2410_pm",
.subsys = &s3c2410_subsys,
.add_dev = s3c2410_pm_add,
};
/* register ourselves */
static int __init s3c2410_pm_drvinit(void)
{
return subsys_interface_register(&s3c2410_pm_interface);
}
arch_initcall(s3c2410_pm_drvinit);
static struct subsys_interface s3c2410a_pm_interface = {
.name = "s3c2410a_pm",
.subsys = &s3c2410a_subsys,
.add_dev = s3c2410_pm_add,
};
static int __init s3c2410a_pm_drvinit(void)
{
return subsys_interface_register(&s3c2410a_pm_interface);
}
arch_initcall(s3c2410a_pm_drvinit);
#endif
#if defined(CONFIG_CPU_S3C2440)
static struct subsys_interface s3c2440_pm_interface = {
.name = "s3c2440_pm",
.subsys = &s3c2440_subsys,
.add_dev = s3c2410_pm_add,
};
static int __init s3c2440_pm_drvinit(void)
{
return subsys_interface_register(&s3c2440_pm_interface);
}
arch_initcall(s3c2440_pm_drvinit);
#endif
#if defined(CONFIG_CPU_S3C2442)
static struct subsys_interface s3c2442_pm_interface = {
.name = "s3c2442_pm",
.subsys = &