void
packet_handle_std_validate(struct packet_handle_std *handle) {

   struct packet_fields * pktout_inport, *pktout_metadata;
   uint32_t in_port;
   uint64_t metadata;
   if(handle->valid)
        return;
        
   if (nblink_packet_parse(handle->pkt->buffer,&handle->match.match_fields, handle->proto) < 0)
        return;
    handle->valid = true;
    
    /* Add in_port value to the hash_map */    
    pktout_inport = (struct packet_fields*) malloc(sizeof(struct packet_fields));	
    pktout_inport->header = OXM_OF_IN_PORT;
    pktout_inport->value = (uint8_t*) malloc(sizeof(uint32_t));
    memset(pktout_inport->value,0x0,sizeof(uint32_t));
    in_port = htonl(handle->pkt->in_port);
    memcpy(pktout_inport->value,&in_port,sizeof(uint32_t));
    hmap_insert(&handle->match.match_fields, &pktout_inport->hmap_node,hash_int(pktout_inport->header, 0));  

    /*Add metadata value to the hash_map */
    pktout_metadata = (struct packet_fields*) malloc(sizeof(struct packet_fields));
    pktout_metadata->header = OXM_OF_METADATA;
    pktout_metadata->value = (uint8_t*) malloc(sizeof(uint64_t) );
    metadata = 0xffffffffffffffff;
    memcpy(pktout_metadata->value, &metadata, sizeof(uint64_t));
    hmap_insert(&handle->match.match_fields, &pktout_metadata->hmap_node,hash_int(pktout_metadata->header, 0));  
    return;
}
Beispiel #2
0
/* Handles meter_mod messages with ADD command. */
static ofl_err
meter_table_add(struct meter_table *table, struct ofl_msg_meter_mod *mod) {

    struct meter_entry *entry;

    if (hmap_first_with_hash(&table->meter_entries, mod->meter_id) != NULL) {
        return ofl_error(OFPET_METER_MOD_FAILED, OFPMMFC_METER_EXISTS);
    }

    if (table->entries_num == DEFAULT_MAX_METER) {
        return ofl_error(OFPET_METER_MOD_FAILED, OFPMMFC_OUT_OF_METERS);
    }

    if (table->bands_num + mod->meter_bands_num > METER_TABLE_MAX_BANDS) {
        return ofl_error(OFPET_METER_MOD_FAILED, OFPMMFC_OUT_OF_BANDS);
    }

    entry = meter_entry_create(table->dp, table, mod);

    hmap_insert(&table->meter_entries, &entry->node, entry->stats->meter_id);

    table->entries_num++;
    table->bands_num += entry->stats->meter_bands_num;
    ofl_msg_free_meter_mod(mod, false);
    return 0;
}
Beispiel #3
0
/* Adds ATTR to SET, which must not already contain an attribute
   with the same name (matched case insensitively).  Ownership of
   ATTR is transferred to SET. */
void
attrset_add (struct attrset *set, struct attribute *attr)
{
  const char *name = attribute_get_name (attr);
  assert (attrset_lookup (set, name) == NULL);
  hmap_insert (&set->map, &attr->node, hash_case_string (name, 0));
}
Beispiel #4
0
/* Handles group mod messages with ADD command. */
static ofl_err
group_table_add(struct group_table *table, struct ofl_msg_group_mod *mod) {

    struct group_entry *entry;

    if (hmap_first_with_hash(&table->entries, mod->group_id) != NULL) {
        return ofl_error(OFPET_GROUP_MOD_FAILED, OFPGMFC_GROUP_EXISTS);
    }

    if (table->entries_num == GROUP_TABLE_MAX_ENTRIES) {
        return ofl_error(OFPET_GROUP_MOD_FAILED, OFPGMFC_OUT_OF_GROUPS);
    }

    if (table->buckets_num + mod->buckets_num > GROUP_TABLE_MAX_BUCKETS) {
        return ofl_error(OFPET_GROUP_MOD_FAILED, OFPGMFC_OUT_OF_BUCKETS);
    }

    entry = group_entry_create(table->dp, table, mod);

    hmap_insert(&table->entries, &entry->node, entry->stats->group_id);

    table->entries_num++;
    table->buckets_num += entry->desc->buckets_num;

    ofl_msg_free_group_mod(mod, false, table->dp->exp);
    return 0;
}
Beispiel #5
0
static struct numa_node *
insert_new_numa_node(int numa_id)
{
    struct numa_node *n = xzalloc(sizeof *n);

    hmap_insert(&all_numa_nodes, &n->hmap_node, hash_int(numa_id, 0));
    ovs_list_init(&n->cores);
    n->numa_id = numa_id;

    return n;
}
void
ofl_structs_match_put16(struct ofl_match *match, uint32_t header, uint16_t value){
    struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv));
    int len = sizeof(uint16_t);
    
    m->header = header;
    m->value = malloc(len);
    memcpy(m->value, &value, len);
    hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0));
    match->header.length += len + 4;
}
void
ofl_structs_match_put_eth(struct ofl_match *match, uint32_t header, uint8_t value[ETH_ADDR_LEN]){
    struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv));
    int len = ETH_ADDR_LEN;

    m->header = header;
    m->value = malloc(len);
    memcpy(m->value, value, len);
    hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0));
    match->header.length += len + 4;

}
void ofl_structs_match_put_ipv6m(struct ofl_match *match, uint32_t header, const struct in6_addr *value, const struct in6_addr *mask){
    struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv));
    int len = sizeof(struct in6_addr);
    
    m->header = header;
    m->value = malloc(len*2);
    memcpy(m->value, &value, len);
    memcpy(m->value + len, &mask, len);
    hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0));
    match->header.length += len*2 + 4;

}
Beispiel #9
0
/* Calculates A = union(A, B) and B = intersect(A, B).

   If only the intersection is needed, string_set_intersect() is
   faster. */
void
string_set_union_and_intersection (struct string_set *a, struct string_set *b)
{
  struct string_set_node *node, *next;

  HMAP_FOR_EACH_SAFE (node, next, struct string_set_node, hmap_node,
                      &b->hmap)
    if (!string_set_find_node__ (a, node->string, node->hmap_node.hash))
      {
        hmap_delete (&b->hmap, &node->hmap_node);
        hmap_insert (&a->hmap, &node->hmap_node, node->hmap_node.hash);
      }
}
void
ofl_structs_match_put_ipv6m(struct ofl_match *match, uint32_t header, uint8_t value[IPv6_ADDR_LEN], uint8_t mask[IPv6_ADDR_LEN]){
    struct ofl_match_tlv *m = malloc(sizeof (struct ofl_match_tlv));
    int len = IPv6_ADDR_LEN;

    m->header = header;
    m->value = malloc(len*2);
    memcpy(m->value, value, len);
    memcpy(m->value + len, mask, len);
    hmap_insert(&match->match_fields,&m->hmap_node,hash_int(header, 0));
    match->header.length += len*2 + 4;

}
Beispiel #11
0
/* Initializes NEW_SET as a new attribute set whose contents are
   initially the same as that of OLD_SET. */
void
attrset_clone (struct attrset *new_set, const struct attrset *old_set)
{
  struct attribute *old_attr;

  attrset_init (new_set);
  HMAP_FOR_EACH (old_attr, struct attribute, node, &old_set->map)
    {
      struct attribute *new_attr = attribute_clone (old_attr);
      hmap_insert (&new_set->map, &new_attr->node,
                   hmap_node_hash (&old_attr->node));
    }
}
Beispiel #12
0
static struct cpu_core *
insert_new_cpu_core(struct numa_node *n, unsigned core_id)
{
    struct cpu_core *c = xzalloc(sizeof *c);

    hmap_insert(&all_cpu_cores, &c->hmap_node, hash_int(core_id, 0));
    ovs_list_insert(&n->cores, &c->list_node);
    c->core_id = core_id;
    c->numa = n;
    c->available = true;

    return c;
}
Beispiel #13
0
/* Creates a new handle with identifier ID (which may be null)
   and name HANDLE_NAME that refers to REFERENT.  Links the new
   handle into the global list.  Returns the new handle.

   The new handle is not fully initialized.  The caller is
   responsible for completing its initialization. */
static struct file_handle *
create_handle (const char *id, char *handle_name, enum fh_referent referent)
{
  struct file_handle *handle = xzalloc (sizeof *handle);

  handle->ref_cnt = 1;
  handle->id = id != NULL ? xstrdup (id) : NULL;
  handle->name = handle_name;
  handle->referent = referent;

  if (id != NULL)
    {
      assert (fh_from_id (id) == NULL);
      hmap_insert (&named_handles, &handle->name_node,
                   hash_case_string (handle->id, 0));
      handle->ref_cnt++;
    }

  return handle;
}
Beispiel #14
0
static void
oxm_init(void)
{
    if (hmap_is_empty(&all_oxm_fields)) {
        int i;

        for (i = 0; i < N_OXM_FIELDS; i++) {
            struct oxm_field *f = &oxm_fields[i];
            hmap_insert(&all_oxm_fields, &f->hmap_node,
                        hash_int(f->header, 0));
        }

        /* Verify that the header values are unique (duplicate "case" values
         * cause a compile error). */
        switch (0) {
#define DEFINE_FIELD(HEADER, DL_TYPE, NW_PROTO, MASKABLE)  \
        case OXM_##HEADER: break;
#include "oxm-match.def"
        }
    }
}
Beispiel #15
0
void init_wk_table(struct hmap *map)
{
	char key[ID_SIZE];
	int value;
	value=KEYWORD_READ;
	strcpy(key, "read");
	hmap_insert(map, key, &value);
    	value=KEYWORD_WRITE;
	strcpy(key, "write");
	hmap_insert(map, key, &value);
	value=KEYWORD_BEGIN;
	strcpy(key, "begin");
	hmap_insert(map, key, &value);	
	value=KEYWORD_END;
	strcpy(key, "end");
	hmap_insert(map, key, &value);	
	value=KEYWORD_CONST;
	strcpy(key, "const");
	hmap_insert(map, key, &value);	
	value=KEYWORD_IF;
	strcpy(key, "if");
	hmap_insert(map, key, &value);	
	value=KEYWORD_ELSE;
	strcpy(key, "else");
	hmap_insert(map, key, &value);	
	value=KEYWORD_PROCEDURE;
	strcpy(key, "procedure");
	hmap_insert(map, key, &value);	
	value=KEYWORD_THEN;
	strcpy(key, "then");
	hmap_insert(map, key, &value);	
	value=KEYWORD_VAR;
	strcpy(key, "var");
	hmap_insert(map, key, &value);	
	value=KEYWORD_WHILE;
	strcpy(key, "while");
	hmap_insert(map, key, &value);	
	value=KEYWORD_FOR;
	strcpy(key, "for");
	hmap_insert(map, key, &value);	
	value=KEYWORD_TO;
	strcpy(key, "to");
	hmap_insert(map, key, &value);	
	value=KEYWORD_DO;
	strcpy(key, "do");
	hmap_insert(map, key, &value);	
	value=KEYWORD_REAL;
	strcpy(key, "real");
	hmap_insert(map, key, &value);	
	value=KEYWORD_INTEGER;
	strcpy(key, "integer");
	hmap_insert(map, key, &value);	
	value=KEYWORD_PROGRAM;
	strcpy(key, "program");
	hmap_insert(map, key, &value);	
}
Beispiel #16
0
/* Parses the whole DO REPEAT command specification.
   Returns success. */
static bool
parse_specification (struct lexer *lexer, struct dictionary *dict,
                     struct hmap *dummies)
{
  struct dummy_var *first_dv = NULL;

  hmap_init (dummies);
  do
    {
      struct dummy_var *dv;
      const char *name;
      bool ok;

      /* Get a stand-in variable name and make sure it's unique. */
      if (!lex_force_id (lexer))
	goto error;
      name = lex_tokcstr (lexer);
      if (dict_lookup_var (dict, name))
        msg (SW, _("Dummy variable name `%s' hides dictionary variable `%s'."),
             name, name);
      if (find_dummy_var (dummies, name, strlen (name)))
        {
          msg (SE, _("Dummy variable name `%s' is given twice."), name);
          goto error;
        }

      /* Make a new macro. */
      dv = xmalloc (sizeof *dv);
      dv->name = xstrdup (name);
      dv->values = NULL;
      dv->n_values = 0;
      hmap_insert (dummies, &dv->hmap_node, hash_dummy (name, strlen (name)));

      /* Skip equals sign. */
      lex_get (lexer);
      if (!lex_force_match (lexer, T_EQUALS))
	goto error;

      /* Get the details of the variable's possible values. */
      if (lex_token (lexer) == T_ID || lex_token (lexer) == T_ALL)
	ok = parse_ids (lexer, dict, dv);
      else if (lex_is_number (lexer))
	ok = parse_numbers (lexer, dv);
      else if (lex_is_string (lexer))
	ok = parse_strings (lexer, dv);
      else
	{
	  lex_error (lexer, NULL);
	  goto error;
	}
      if (!ok)
	goto error;
      assert (dv->n_values > 0);
      if (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
        {
          lex_error (lexer, NULL);
          goto error;
        }

      /* If this is the first variable then it defines how many replacements
	 there must be; otherwise enforce this number of replacements. */
      if (first_dv == NULL)
        first_dv = dv;
      else if (first_dv->n_values != dv->n_values)
	{
	  msg (SE, _("Dummy variable `%s' had %zu substitutions, so `%s' must "
                     "also, but %zu were specified."),
               first_dv->name, first_dv->n_values,
               dv->name, dv->n_values);
	  goto error;
	}

      lex_match (lexer, T_SLASH);
    }
  while (!lex_match (lexer, T_ENDCMD));

  while (lex_match (lexer, T_ENDCMD))
    continue;

  return true;

error:
  destroy_dummies (dummies);
  return false;
}
Beispiel #17
0
extern "C" int nbee_link_convertpkt(struct ofpbuf * pktin, struct hmap * pktout)
{
	//pkhdr->ts.tv_sec = 0;
	pkhdr->caplen = pktin->size; //need this information
	pkhdr->len = pktin->size; //need this information

	_nbPDMLPacket * curr_packet;

	// Decode packet
	if (Decoder->DecodePacket(LinkLayerType, PacketCounter, pkhdr, (const unsigned char*) (pktin->data)) == nbFAILURE)
	{
		printf("\nError decoding a packet %s\n\n", Decoder->GetLastError());
		// Let's break and save what we've done so far
		return -1;
	}

	PDMLReader->GetCurrentPacket(&curr_packet);

	_nbPDMLProto * proto;
	_nbPDMLField * field;

	proto = curr_packet->FirstProto;

	while (1)
        {
        	field = proto->FirstField;
              	while(1)
               	{
			
			if((char)field->LongName[0]<58 && (char)field->LongName[0]>47 && field->isField )
                        {
				/* A value between 47 and 58 indicates a field defined for Matching */
	                        int i,pow;
                                uint32_t type;
                                uint8_t size;
				packet_fields_t * pktout_field;
		                pktout_field = (packet_fields_t*) malloc(sizeof(packet_fields_t));


                                field_values_t *new_field;
                                new_field = (field_values_t *)malloc(sizeof(field_values_t));
				new_field->len = (uint32_t) field->Size;

                                for (type=0,i=0,pow=100;i<3;i++,pow = (pow==1 ? pow : pow/10))
        	                        type = type + (pow*(field->LongName[i]-48));
		                        
				size = field->Size;

                                pktout_field->header = NXM_HEADER(VENDOR_FROM_TYPE(type),FIELD_FROM_TYPE(type),size); 
                                new_field->value = (uint8_t*) malloc(field->Size);
                                memcpy(new_field->value,((uint8_t*)pktin->data + field->Position),field->Size);

				packet_fields_t *iter;
				bool done=0;
				HMAP_FOR_EACH(iter,packet_fields_t, hmap_node,pktout)
				{
					if(iter->header == pktout_field->header)
					{
						/* Adding entry to existing hash entry */
						list_t_push_back(&iter->fields,&new_field->list_node);
						done=1;
						break;
					}
				}

				if (!done)
				{
					/* Creating new hash map entry */
					list_t_init(&pktout_field->fields);
                                	list_t_push_back(&pktout_field->fields,&new_field->list_node);
                                	hmap_insert(pktout, &pktout_field->hmap_node,
	                        	hash_int(pktout_field->header, 0));
				}
				done =0;

			}

			if(field->NextField == NULL && field->ParentField == NULL) 
			{
				/* Protocol Done */
				break;
			}
			else if (field->NextField == NULL && field->ParentField != NULL)
			{
				field = field->ParentField;
			}
			else if (!field->NextField->isField)
			{

				if ((char)field->NextField->LongName[0]<58 && (char)field->NextField->LongName[0]>47)
				{
		                        int i,pow;
	                                uint32_t type;
					packet_fields_t * pktout_field;
			                pktout_field = (packet_fields_t*) malloc(sizeof(packet_fields_t));

		                        field_values_t *new_field;
                	                new_field = (field_values_t *)malloc(sizeof(field_values_t));

					for (type=0,i=0,pow=100;i<3;i++,pow = (pow==1 ? pow : pow/10))
        	                        	type = type + (pow*(field->NextField->LongName[i]-48));
								
				        new_field->value = (uint8_t*) malloc(field->Size);
					_nbPDMLField * nbPrevField; 
				
					if( !field->isField)
						nbPrevField = field->FirstChild;
					else
						nbPrevField = proto->FirstField;

					string NextHeader ("nexthdr");
					bool found = true;
					while(NextHeader.compare(nbPrevField->Name))
					{
						if(nbPrevField->NextField != NULL)
							nbPrevField=nbPrevField->NextField;
						else
						{
							found = false ;
							break;
						}
					}

					if (found)
					{
                        pktout_field->header = NXM_HEADER(VENDOR_FROM_TYPE(type),FIELD_FROM_TYPE(type),nbPrevField->Size);
	                    memcpy(new_field->value,((uint8_t*)pktin->data + nbPrevField->Position),nbPrevField->Size);	
						new_field->len = (uint32_t) nbPrevField->Size;

						packet_fields_t *iter;
						bool done=0;
						HMAP_FOR_EACH(iter,packet_fields_t, hmap_node,pktout)
						{
							if(iter->header == pktout_field->header)
							{
								/* Adding entry to existing hash entry */
								done=1;
								break;
							}
						}
	
						if (!done)
						{
							/* Creating new hash map entry */
							list_t_init(&pktout_field->fields);
		                                	list_t_push_back(&pktout_field->fields,&new_field->list_node);
		                                	hmap_insert(pktout, &pktout_field->hmap_node,
			                        	hash_int(pktout_field->header, 0));
						}
					}
				}
				/* Next field is a block. */
				field = field->NextField->FirstChild;
			}
			else
			{