X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_vnet_core.c;h=a2d06f2ffeeab465ce9dc78b607f80864b56d1b0;hb=0a7690f54cb5bda83780dac26ce433ad24b1d766;hp=6baef5ad04972bfabf9ba542903f86df7f8865e4;hpb=22dbf90548cb2ea56a9057a706e3da411dc1b57b;p=palacios.git diff --git a/palacios/src/palacios/vmm_vnet_core.c b/palacios/src/palacios/vmm_vnet_core.c index 6baef5a..a2d06f2 100644 --- a/palacios/src/palacios/vmm_vnet_core.c +++ b/palacios/src/palacios/vmm_vnet_core.c @@ -46,7 +46,10 @@ struct vnet_dev { void * private_data; int active; - uint8_t mode; //vmm_drivern or guest_drivern + nic_poll_type_t mode; /*vmm_drivern or guest_drivern */ + + uint64_t bytes_tx, bytes_rx; + uint32_t pkts_tx, pkt_rx; struct list_head node; } __attribute__((packed)); @@ -57,7 +60,7 @@ struct vnet_brg_dev { struct v3_vnet_bridge_ops brg_ops; uint8_t type; - uint8_t mode; + nic_poll_type_t mode; int active; void * private_data; } __attribute__((packed)); @@ -90,9 +93,10 @@ static struct { int num_routes; int num_devs; - struct vnet_brg_dev *bridge; + struct vnet_brg_dev * bridge; v3_lock_t lock; + struct vnet_stat stats; struct hashtable * route_cache; } vnet_state; @@ -101,46 +105,47 @@ static struct { #ifdef CONFIG_DEBUG_VNET static inline void mac_to_string(uint8_t * mac, char * buf) { - snprintf(buf, 100, "%d:%d:%d:%d:%d:%d", + snprintf(buf, 100, "%2x:%2x:%2x:%2x:%2x:%2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } -static void print_route(struct vnet_route_info * route){ +static void print_route(struct v3_vnet_route * route){ char str[50]; - mac_to_string(route->route_def.src_mac, str); + mac_to_string(route->src_mac, str); PrintDebug("Src Mac (%s), src_qual (%d)\n", - str, route->route_def.src_mac_qual); - mac_to_string(route->route_def.dst_mac, str); + str, route->src_mac_qual); + mac_to_string(route->dst_mac, str); PrintDebug("Dst Mac (%s), dst_qual (%d)\n", - str, route->route_def.dst_mac_qual); + str, route->dst_mac_qual); PrintDebug("Src dev id (%d), src type (%d)", - route->route_def.src_id, - route->route_def.src_type); + route->src_id, + route->src_type); PrintDebug("Dst dev id (%d), dst type (%d)\n", - route->route_def.dst_id, - route->route_def.dst_type); - if (route->route_def.dst_type == LINK_INTERFACE) { - PrintDebug("dst_dev (%p), dst_dev_id (%d), dst_dev_ops(%p), dst_dev_data (%p)\n", - route->dst_dev, - route->dst_dev->dev_id, - (void *)&(route->dst_dev->dev_ops), - route->dst_dev->private_data); - } + route->dst_id, + route->dst_type); } static void dump_routes(){ - struct vnet_route_info *route; + struct vnet_route_info *route; - int i = 0; - PrintDebug("\n========Dump routes starts ============\n"); - list_for_each_entry(route, &(vnet_state.routes), node) { - PrintDebug("\nroute %d:\n", i++); + int i = 0; + PrintDebug("\n========Dump routes starts ============\n"); + list_for_each_entry(route, &(vnet_state.routes), node) { + PrintDebug("\nroute %d:\n", i++); - print_route(route); + print_route(&(route->route_def)); + if (route->route_def.dst_type == LINK_INTERFACE) { + PrintDebug("dst_dev (%p), dst_dev_id (%d), dst_dev_ops(%p), dst_dev_data (%p)\n", + route->dst_dev, + route->dst_dev->dev_id, + (void *)&(route->dst_dev->dev_ops), + route->dst_dev->private_data); } - PrintDebug("\n========Dump routes end ============\n"); + } + + PrintDebug("\n========Dump routes end ============\n"); } #endif @@ -202,14 +207,28 @@ static struct vnet_dev * dev_by_mac(uint8_t * mac) { struct vnet_dev * dev = NULL; list_for_each_entry(dev, &(vnet_state.devs), node) { - if (!memcmp(dev->mac_addr, mac, ETH_ALEN)) + if (!compare_ethaddr(dev->mac_addr, mac)){ return dev; + } } return NULL; } +int v3_vnet_find_dev(uint8_t * mac) { + struct vnet_dev * dev = NULL; + + dev = dev_by_mac(mac); + + if(dev != NULL) { + return dev->dev_id; + } + + return -1; +} + + int v3_vnet_add_route(struct v3_vnet_route route) { struct vnet_route_info * new_route = NULL; unsigned long flags; @@ -217,8 +236,10 @@ int v3_vnet_add_route(struct v3_vnet_route route) { new_route = (struct vnet_route_info *)V3_Malloc(sizeof(struct vnet_route_info)); memset(new_route, 0, sizeof(struct vnet_route_info)); - PrintDebug("VNET/P Core: add_route_entry: dst_id: %d, dst_type: %d\n", - route.dst_id, route.dst_type); +#ifdef CONFIG_DEBUG_VNET + PrintDebug("VNET/P Core: add_route_entry:\n"); + print_route(&route); +#endif memcpy(new_route->route_def.src_mac, route.src_mac, ETH_ALEN); memcpy(new_route->route_def.dst_mac, route.dst_mac, ETH_ALEN); @@ -226,31 +247,18 @@ int v3_vnet_add_route(struct v3_vnet_route route) { new_route->route_def.dst_mac_qual = route.dst_mac_qual; new_route->route_def.dst_type = route.dst_type; new_route->route_def.src_type = route.src_type; - - if(route.dst_id == -1){ - if (new_route->route_def.dst_type == LINK_INTERFACE) { - new_route->dst_dev = dev_by_mac(route.dst_mac); - } - new_route->route_def.dst_id = new_route->dst_dev->dev_id; - } else { - new_route->route_def.dst_id = route.dst_id; - if (new_route->route_def.dst_type == LINK_INTERFACE) { - new_route->dst_dev = dev_by_id(new_route->route_def.dst_id); - } + new_route->route_def.src_id = route.src_id; + new_route->route_def.dst_id = route.dst_id; + + if (new_route->route_def.dst_type == LINK_INTERFACE) { + new_route->dst_dev = dev_by_id(new_route->route_def.dst_id); } - if(route.src_id == -1){ - if (new_route->route_def.src_type == LINK_INTERFACE) { - new_route->src_dev = dev_by_mac(route.src_mac); - } - new_route->route_def.src_id = new_route->src_dev->dev_id; - } else { - new_route->route_def.src_id = route.src_id; - if (new_route->route_def.src_type == LINK_INTERFACE) { - new_route->src_dev = dev_by_id(new_route->route_def.src_id); - } + if (new_route->route_def.src_type == LINK_INTERFACE) { + new_route->src_dev = dev_by_id(new_route->route_def.src_id); } + flags = v3_lock_irqsave(vnet_state.lock); list_add(&(new_route->node), &(vnet_state.routes)); @@ -299,8 +307,8 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { int max_rank = 0; struct list_head match_list; struct eth_hdr * hdr = (struct eth_hdr *)(pkt->data); - uint8_t src_type = pkt->src_type; - uint32_t src_link = pkt->src_id; + // uint8_t src_type = pkt->src_type; + // uint32_t src_link = pkt->src_id; #ifdef CONFIG_DEBUG_VNET { @@ -332,14 +340,15 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { list_for_each_entry(route, &(vnet_state.routes), node) { struct v3_vnet_route * route_def = &(route->route_def); +/* // CHECK SOURCE TYPE HERE if ( (route_def->src_type != LINK_ANY) && ( (route_def->src_type != src_type) || ( (route_def->src_id != src_link) && - (route_def->src_id != (uint32_t)-1)))) { + (route_def->src_id != -1)))) { continue; } - +*/ if ((route_def->dst_mac_qual == MAC_ANY) && (route_def->src_mac_qual == MAC_ANY)) { @@ -434,6 +443,9 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { flags = v3_lock_irqsave(vnet_state.lock); + vnet_state.stats.rx_bytes += pkt->size; + vnet_state.stats.rx_pkts++; + look_into_cache(pkt, &matched_routes); if (matched_routes == NULL) { PrintDebug("VNET/P Core: send pkt Looking into routing table\n"); @@ -470,6 +482,8 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { PrintDebug("VNET/P Core: Packet not sent properly to bridge\n"); continue; } + vnet_state.stats.tx_bytes += pkt->size; + vnet_state.stats.tx_pkts ++; } else if (route->route_def.dst_type == LINK_INTERFACE) { if (route->dst_dev == NULL || route->dst_dev->active == 0){ PrintDebug("VNET/P Core: No active device to sent data to\n"); @@ -480,6 +494,8 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { PrintDebug("VNET/P Core: Packet not sent properly\n"); continue; } + vnet_state.stats.tx_bytes += pkt->size; + vnet_state.stats.tx_pkts ++; } else { PrintError("VNET/P Core: Wrong dst type\n"); } @@ -553,6 +569,15 @@ int v3_vnet_del_dev(int dev_id){ return 0; } +int v3_vnet_stat(struct vnet_stat * stats){ + + stats->rx_bytes = vnet_state.stats.rx_bytes; + stats->rx_pkts = vnet_state.stats.rx_pkts; + stats->tx_bytes = vnet_state.stats.tx_bytes; + stats->tx_pkts = vnet_state.stats.tx_pkts; + + return 0; +} static void free_devices(){ struct vnet_dev * dev = NULL; @@ -573,29 +598,6 @@ static void free_routes(){ } } -/* TODO: Round-bin or ?? */ -void v3_vnet_poll(struct v3_vm_info * vm){ - struct vnet_dev * dev = NULL; - struct vnet_brg_dev *bridge = vnet_state.bridge; - - list_for_each_entry(dev, &(vnet_state.devs), node) { - if(dev->mode == VMM_DRIVERN && - dev->active && - dev->vm == vm){ - - dev->dev_ops.poll(vm, dev->private_data); - } - } - - if (bridge != NULL && - bridge->active && - bridge->mode == VMM_DRIVERN) { - - bridge->brg_ops.poll(bridge->vm, bridge->private_data); - } - -} - int v3_vnet_add_bridge(struct v3_vm_info * vm, struct v3_vnet_bridge_ops * ops, uint8_t type, @@ -643,6 +645,20 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, } +void v3_vnet_do_poll(struct v3_vm_info * vm){ + struct vnet_dev * dev = NULL; + + /* TODO: run this on separate threads + * round-robin schedule, with maximal budget for each poll + */ + list_for_each_entry(dev, &(vnet_state.devs), node) { + if(dev->mode == VMM_DRIVERN){ + dev->dev_ops.poll(vm, -1, dev->private_data); + } + } +} + + int v3_init_vnet() { memset(&vnet_state, 0, sizeof(vnet_state));