summaryrefslogtreecommitdiffstats
path: root/kernel/include/linux/hdlcdrv.h
blob: be3be25bb898f549376945e9ad5fd6a365e40ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * hdlcdrv.h  -- HDLC packet radio network driver.
 * The Linux soundcard driver for 1200 baud and 9600 baud packet radio
 * (C) 1996-1998 by Thomas Sailer, HB9JNX/AE4WA
 */
#ifndef _HDLCDRV_H
#define _HDLCDRV_H


#include <linux/netdevice.h>
#include <linux/if.h>
#include <linux/spinlock.h>
#include <uapi/linux/hdlcdrv.h>

#define HDLCDRV_MAGIC      0x5ac6e778
#define HDLCDRV_HDLCBUFFER  32 /* should be a power of 2 for speed reasons */
#define HDLCDRV_BITBUFFER  256 /* should be a power of 2 for speed reasons */
#undef HDLCDRV_LOOPBACK  /* define for HDLC debugging purposes */
#define HDLCDRV_DEBUG

/* maximum packet length, excluding CRC */
#define HDLCDRV_MAXFLEN             400	


struct hdlcdrv_hdlcbuffer {
	spinlock_t lock;
	unsigned rd, wr;
	unsigned short buf[HDLCDRV_HDLCBUFFER];
};

#ifdef HDLCDRV_DEBUG
struct hdlcdrv_bitbuffer {
	unsigned int rd;
	unsigned int wr;
	unsigned int shreg;
	unsigned char buffer[HDLCDRV_BITBUFFER];
};

static inline void hdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer *buf, 
					 unsigned int bit)
{
	unsigned char new;

	new = buf->shreg & 1;
	buf->shreg >>= 1;
	buf->shreg |= (!!bit) << 7;
	if (new) {
		buf->buffer[buf->wr] = buf->shreg;
		buf->wr = (buf->wr+1) % sizeof(buf->buffer);
		buf->shreg = 0x80;
	}
}

static inline void hdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer *buf, 
					      unsigned int bits)
{
	buf->buffer[buf->wr] = bits & 0xff;
	buf->wr = (buf->wr+1) % sizeof(buf->buffer);
	buf->buffer[buf->wr] = (bits >> 8) & 0xff;
	buf->wr = (buf->wr+1) % sizeof(buf->buffer);

}
#endif /* HDLCDRV_DEBUG */

/* -------------------------------------------------------------------- */
/*
 * Information that need to be kept for each driver. 
 */

struct hdlcdrv_ops {
	/*
	 * first some informations needed by the hdlcdrv routines
	 */
	const char *drvname;
	const char *drvinfo;
	/*
	 * the routines called by the hdlcdrv routines
	 */
	int (*open)(struct net_device *);
	int (*close)(struct net_device *);
	int (*ioctl)(struct net_device *, struct ifreq *, 
		     struct hdlcdrv_ioctl *, int);
};

struct hdlcdrv_state {
	int magic;
	int opened;

	const struct hdlcdrv_ops *ops;

	struct {
		int bitrate;
	} par;

	struct hdlcdrv_pttoutput {
		int dma2;
		int seriobase;
		int pariobase;
		int midiiobase;
		unsigned int flags;
	} ptt_out;

	struct hdlcdrv_channel_params ch_params;

	struct hdlcdrv_hdlcrx {
		struct hdlcdrv_hdlcbuffer hbuf;
		unsigned long in_hdlc_rx;
		/* 0 = sync hunt, != 0 receiving */
		int rx_state;	
		unsigned int bitstream;
		unsigned int bitbuf;
		int numbits;
		unsigned char dcd;
		
		int len;
		unsigned char *bp;
		unsigned char buffer[HDLCDRV_MAXFLEN+2];
	} hdlcrx;

	struct hdlcdrv_hdlctx {
		struct hdlcdrv_hdlcbuffer hbuf;
		unsigned long in_hdlc_tx;
		/*
		 * 0 = send flags
		 * 1 = send txtail (flags)
		 * 2 = send packet
		 */
		int tx_state;	
		int numflags;
		unsigned int bitstream;
		unsigned char ptt;
		int calibrate;
		int slotcnt;

		unsigned int bitbuf;
		int numbits;
		
		int len;
		unsigned char *bp;
		unsigned char buffer[HDLCDRV_MAXFLEN+2];
	} hdlctx;

#ifdef HDLCDRV_DEBUG
	struct hdlcdrv_bitbuffer bitbuf_channel;
	struct hdlcdrv_bitbuffer bitbuf_hdlc;
#endif /* HDLCDRV_DEBUG */

	int ptt_keyed;

	/* queued skb for transmission */
	struct sk_buff *skb;
};


/* -------------------------------------------------------------------- */

static inline int hdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer *hb) 
{
	unsigned long flags;
	int ret;
	
	spin_lock_irqsave(&hb->lock, flags);
	ret = !((HDLCDRV_HDLCBUFFER - 1 + hb->rd - hb->wr) % HDLCDRV_HDLCBUFFER);
	spin_unlock_irqrestore(&hb->lock, flags);
	return ret;
}

/* -------------------------------------------------------------------- */

static inline int hdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer *hb)
{
	unsigned long flags;
	int ret;
	
	spin_lock_irqsave(&hb->lock, flags);
	ret = (hb->rd == hb->wr);
	spin_unlock_irqrestore(&hb->lock, flags);
	return ret;
}

/* -------------------------------------------------------------------- */

static inline unsigned short hdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer *hb)
{
	unsigned long flags;
	unsigned short val;
	unsigned newr;

	spin_lock_irqsave(&hb->lock, flags);
	if (hb->rd == hb->wr)
		val = 0;
	else {
		newr = (hb->rd+1) % HDLCDRV_HDLCBUFFER;
		val = hb->buf[hb->rd];
		hb->rd = newr;
	}
	spin_unlock_irqrestore(&hb->lock, flags);
	return val;
}

/* -------------------------------------------------------------------- */

static inline void hdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer *hb, 
				    unsigned short val)
{
	unsigned newp;
	unsigned long flags;
	
	spin_lock_irqsave(&hb->lock, flags);
	newp = (hb->wr+1) % HDLCDRV_HDLCBUFFER;
	if (newp != hb->rd) { 
		hb->buf[hb->wr] = val & 0xffff;
		hb->wr = newp;
	}
	spin_unlock_irqrestore(&hb->lock, flags);
}

/* -------------------------------------------------------------------- */

static inline void hdlcdrv_putbits(struct hdlcdrv_state *s, unsigned int bits)
{
	hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, bits);
}

static inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state *s)
{
	unsigned int ret;

	if (hdlcdrv_hbuf_empty(&s->hdlctx.hbuf)) {
		if (s->hdlctx.calibrate > 0)
			s->hdlctx.calibrate--;
		else
			s->hdlctx.ptt = 0;
		ret = 0;
	} else 
		ret = hdlcdrv_hbuf_get(&s->hdlctx.hbuf);
#ifdef HDLCDRV_LOOPBACK
	hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, ret);
#endif /* HDLCDRV_LOOPBACK */
	return ret;
}

static inline void hdlcdrv_channelbit(struct hdlcdrv_state *s, unsigned int bit)
{
#ifdef HDLCDRV_DEBUG
	hdlcdrv_add_bitbuffer(&s->bitbuf_channel, bit);
#endif /* HDLCDRV_DEBUG */
}

static inline void hdlcdrv_setdcd(struct hdlcdrv_state *s, int dcd)
{
	s->hdlcrx.dcd = !!dcd;
}

static inline int hdlcdrv_ptt(struct hdlcdrv_state *s)
{
	return s->hdlctx.ptt || (s->hdlctx.calibrate > 0);
}

/* -------------------------------------------------------------------- */

void hdlcdrv_receiver(struct net_device *, struct hdlcdrv_state *);
void hdlcdrv_transmitter(struct net_device *, struct hdlcdrv_state *);
void hdlcdrv_arbitrate(struct net_device *, struct hdlcdrv_state *);
struct net_device *hdlcdrv_register(const struct hdlcdrv_ops *ops,
				    unsigned int privsize, const char *ifname,
				    unsigned int baseaddr, unsigned int irq, 
				    unsigned int dma);
void hdlcdrv_unregister(struct net_device *dev);

/* -------------------------------------------------------------------- */



#endif /* _HDLCDRV_H */
> network_dic = {'net_id': network_id, 'subnet_id': subnet_id, 'router_id': router_id} return network_dic def create_glance_image(path, name, disk_format): """ Create a glance image given the absolute path of the image, its name and the disk format """ cmd = ("glance image-create --name "+name+" --visibility public " "--disk-format "+disk_format+" --container-format bare --file "+path) functest_utils.execute_command(cmd, logger) return True def delete_glance_image(name): cmd = ("glance image-delete $(glance image-list | grep %s " "| awk '{print $2}' | head -1)" % name) functest_utils.execute_command(cmd, logger) return True def cleanup(nova, neutron, network_dic, port_id1, port_id2): # delete both VMs logger.info("Cleaning up...") logger.debug("Deleting image...") delete_glance_image(GLANCE_IMAGE_NAME) vm1 = functest_utils.get_instance_by_name(nova, NAME_VM_1) if vm1: logger.debug("Deleting '%s'..." % NAME_VM_1) nova.servers.delete(vm1) # wait until VMs are deleted if not waitVmDeleted(nova, vm1): logger.error( "Instance '%s' with cannot be deleted. Status is '%s'" % ( NAME_VM_1, functest_utils.get_instance_status(nova, vm1))) else: logger.debug("Instance %s terminated." % NAME_VM_1) vm2 = functest_utils.get_instance_by_name(nova, NAME_VM_2) if vm2: logger.debug("Deleting '%s'..." % NAME_VM_2) vm2 = nova.servers.find(name=NAME_VM_2) nova.servers.delete(vm2) if not waitVmDeleted(nova, vm2): logger.error( "Instance '%s' with cannot be deleted. Status is '%s'" % ( NAME_VM_2, functest_utils.get_instance_status(nova, vm2))) else: logger.debug("Instance %s terminated." % NAME_VM_2) # delete created network logger.info("Deleting network '%s'..." % NEUTRON_PRIVATE_NET_NAME) net_id = network_dic["net_id"] subnet_id = network_dic["subnet_id"] router_id = network_dic["router_id"] if not functest_utils.delete_neutron_port(neutron, port_id1): logger.error("Unable to remove port '%s'" % port_id1) return False logger.debug("Port '%s' removed successfully" % port_id1) if not functest_utils.delete_neutron_port(neutron, port_id2): logger.error("Unable to remove port '%s'" % port_id2) return False logger.debug("Port '%s' removed successfully" % port_id2) if not functest_utils.remove_interface_router(neutron, router_id, subnet_id): logger.error("Unable to remove subnet '%s' from router '%s'" % ( subnet_id, router_id)) return False logger.debug("Interface removed successfully") if not functest_utils.delete_neutron_router(neutron, router_id): logger.error("Unable to delete router '%s'" % router_id) return False logger.debug("Router deleted successfully") if not functest_utils.delete_neutron_subnet(neutron, subnet_id): logger.error("Unable to delete subnet '%s'" % subnet_id) return False logger.debug( "Subnet '%s' deleted successfully" % NEUTRON_PRIVATE_SUBNET_NAME) if not functest_utils.delete_neutron_net(neutron, net_id): logger.error("Unable to delete network '%s'" % net_id) return False logger.debug( "Network '%s' deleted successfully" % NEUTRON_PRIVATE_NET_NAME) return True def main(): creds_nova = functest_utils.get_credentials("nova") nova_client = novaclient.Client(**creds_nova) creds_neutron = functest_utils.get_credentials("neutron") neutron_client = neutronclient.Client(**creds_neutron) EXIT_CODE = -1 image = None flavor = None logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH)) create_glance_image(GLANCE_IMAGE_PATH, GLANCE_IMAGE_NAME, GLANCE_IMAGE_FORMAT) # Check if the given image exists try: image = nova_client.images.find(name=GLANCE_IMAGE_NAME) logger.info("Glance image found '%s'" % GLANCE_IMAGE_NAME) except: logger.error("ERROR: Glance image '%s' not found." % GLANCE_IMAGE_NAME) logger.info("Available images are: ") pMsg(nova_client.images.list()) exit(-1) network_dic = create_private_neutron_net(neutron_client) if not network_dic: logger.error( "There has been a problem when creating the neutron network") exit(-1) network_id = network_dic["net_id"] # Check if the given flavor exists try: flavor = nova_client.flavors.find(name=FLAVOR) logger.info("Flavor found '%s'" % FLAVOR) except: logger.error("Flavor '%s' not found." % FLAVOR) logger.info("Available flavors are: ") pMsg(nova_client.flavor.list()) exit(-1) # Deleting instances if they exist servers = nova_client.servers.list() for server in servers: if server.name == NAME_VM_1 or server.name == NAME_VM_2: logger.info("Instance %s found. Deleting..." % server.name) server.delete() # boot VM 1 # basic boot # tune (e.g. flavor, images, network) to your specific # openstack configuration here # we consider start time at VM1 booting start_time_ts = time.time() end_time_ts = start_time_ts logger.info("vPing Start Time:'%s'" % ( datetime.datetime.fromtimestamp(start_time_ts).strftime( '%Y-%m-%d %H:%M:%S'))) # create VM logger.debug("Creating port 'vping-port-1' with IP %s..." % IP_1) port_id1 = functest_utils.create_neutron_port(neutron_client, "vping-port-1", network_id, IP_1) if not port_id1: logger.error("Unable to create port.") exit(-1) logger.info("Creating instance '%s' with IP %s..." % (NAME_VM_1, IP_1)) logger.debug( "Configuration:\n name=%s \n flavor=%s \n image=%s \n " "network=%s \n" % (NAME_VM_1, flavor, image, network_id)) vm1 = nova_client.servers.create( name=NAME_VM_1, flavor=flavor, image=image, # nics = [{"net-id": network_id, "v4-fixed-ip": IP_1}] nics=[{"port-id": port_id1}] ) # wait until VM status is active if not waitVmActive(nova_client, vm1): logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( NAME_VM_1, functest_utils.get_instance_status(nova_client, vm1))) cleanup(nova_client, neutron_client, network_dic) return (EXIT_CODE) else: logger.info("Instance '%s' is ACTIVE." % NAME_VM_1) # Retrieve IP of first VM # logger.debug("Fetching IP...") # server = functest_utils.get_instance_by_name(nova_client, NAME_VM_1) # theoretically there is only one IP address so we take the # first element of the table # Dangerous! To be improved! # test_ip = server.networks.get(NEUTRON_PRIVATE_NET_NAME)[0] test_ip = IP_1 logger.debug("Instance '%s' got %s" % (NAME_VM_1, test_ip)) # boot VM 2 # we will boot then execute a ping script with cloud-init # the long chain corresponds to the ping procedure converted with base 64 # tune (e.g. flavor, images, network) to your specific openstack # configuration here u = "#!/bin/sh\n\nwhile true; do\n ping -c 1 %s 2>&1 >/dev/null\n " \ "RES=$?\n if [ \"Z$RES\" = \"Z0\" ] ; then\n echo 'vPing OK'\n " \ "break\n else\n echo 'vPing KO'\n fi\n sleep 1\ndone\n" % test_ip # create VM logger.debug("Creating port 'vping-port-2' with IP %s..." % IP_2) port_id2 = functest_utils.create_neutron_port(neutron_client, "vping-port-2", network_id, IP_2) if not port_id2: logger.error("Unable to create port.") exit(-1) logger.info("Creating instance '%s' with IP %s..." % (NAME_VM_2, IP_2)) logger.debug( "Configuration:\n name=%s \n flavor=%s \n image=%s \n network=%s " "\n userdata= \n%s" % ( NAME_VM_2, flavor, image, network_id, u)) vm2 = nova_client.servers.create( name=NAME_VM_2, flavor=flavor, image=image, # nics = [{"net-id": network_id, "v4-fixed-ip": IP_2}], nics=[{"port-id": port_id2}], userdata=u ) if not waitVmActive(nova_client, vm2): logger.error("Instance '%s' cannot be booted. Status is '%s'" % ( NAME_VM_2, functest_utils.get_instance_status(nova_client, vm2))) cleanup(nova_client, neutron_client, network_dic) return (EXIT_CODE) else: logger.info("Instance '%s' is ACTIVE." % NAME_VM_2) logger.info("Waiting for ping...") sec = 0 console_log = vm2.get_console_output() while True: time.sleep(1) console_log = vm2.get_console_output() # print "--"+console_log # report if the test is failed if "vPing OK" in console_log: logger.info("vPing detected!") # we consider start time at VM1 booting end_time_ts = time.time() duration = round(end_time_ts - start_time_ts, 1) logger.info("vPing duration:'%s'" % duration) EXIT_CODE = 0 break elif sec == PING_TIMEOUT: logger.info("Timeout reached.") break else: logger.debug("No vPing detected...") sec += 1 cleanup(nova_client, neutron_client, network_dic, port_id1, port_id2) test_status = "NOK" if EXIT_CODE == 0: logger.info("vPing OK") test_status = "OK" else: logger.error("vPing FAILED") try: if args.report: logger.debug("Push result into DB") # TODO check path result for the file git_version = functest_utils.get_git_branch(args.repo_path) pod_name = functest_utils.get_pod_name(logger) functest_utils.push_results_to_db(TEST_DB, "vPing", logger, pod_name, git_version, payload={'timestart': start_time_ts, 'duration': duration, 'status': test_status}) # with open("vPing-result.json", "w") as outfile: # json.dump({'timestart': start_time_ts, 'duration': duration, # 'status': test_status}, outfile, indent=4) except: logger.error("Error pushing results into Database") exit(EXIT_CODE) if __name__ == '__main__': main()