Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacio...
[palacios.git] / palacios / src / palacios / vmm_vnet_core.c
index 3726c41..18720b1 100644 (file)
@@ -105,27 +105,27 @@ static inline void mac_to_string(char mac[6], char * buf) {
             mac[3], mac[4], mac[5]);
 }
 
-static void print_route(struct vnet_route_info *route){
+static void print_route(struct vnet_route_info * route){
     char str[50];
 
     mac_to_string(route->route_def.src_mac, str);
     PrintDebug("Src Mac (%s),  src_qual (%d)\n", 
-                       str, route->route_def.src_mac_qual);
+              str, route->route_def.src_mac_qual);
     mac_to_string(route->route_def.dst_mac, str);
     PrintDebug("Dst Mac (%s),  dst_qual (%d)\n", 
-                       str, route->route_def.dst_mac_qual);
+              str, route->route_def.dst_mac_qual);
     PrintDebug("Src dev id (%d), src type (%d)", 
-                       route->route_def.src_id, 
-                       route->route_def.src_type);
+              route->route_def.src_id, 
+              route->route_def.src_type);
     PrintDebug("Dst dev id (%d), dst type (%d)\n", 
-                       route->route_def.dst_id, 
-                       route->route_def.dst_type);
+              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_dev,
+              route->dst_dev->dev_id,
+              (void *)&(route->dst_dev->dev_ops),
+              route->dst_dev->private_data);
     }
 }
 
@@ -135,9 +135,9 @@ static void dump_routes(){
        int i = 0;
        PrintDebug("\n========Dump routes starts ============\n");
        list_for_each_entry(route, &(vnet_state.routes), node) {
-               PrintDebug("\nroute %d:\n", ++i);
+           PrintDebug("\nroute %d:\n", i++);
                
-               print_route(route);
+           print_route(route);
        }
        PrintDebug("\n========Dump routes end ============\n");
 }
@@ -229,7 +229,7 @@ int v3_vnet_add_route(struct v3_vnet_route route) {
     memset(new_route, 0, sizeof(struct vnet_route_info));
 
     PrintDebug("Vnet: vnet_add_route_entry: dst_id: %d, dst_type: %d\n",
-                       route.dst_id, route.dst_type);  
+              route.dst_id, route.dst_type);   
     
     memcpy(new_route->route_def.src_mac, route.src_mac, 6);
     memcpy(new_route->route_def.dst_mac, route.dst_mac, 6);
@@ -264,6 +264,27 @@ int v3_vnet_add_route(struct v3_vnet_route route) {
 }
 
 
+/* delete all route entries with specfied src or dst device id */ 
+static void inline del_routes(int dev_id){
+    struct vnet_route_info * route = NULL;
+    unsigned long flags; 
+
+    flags = v3_lock_irqsave(vnet_state.lock);
+
+    list_for_each_entry(route, &(vnet_state.routes), node) {
+       if((route->route_def.dst_type == LINK_INTERFACE &&
+            route->route_def.dst_id == dev_id) ||
+            (route->route_def.src_type == LINK_INTERFACE &&
+             route->route_def.src_id == dev_id)){
+             
+           list_del(&(route->node));
+           list_del(&(route->match_node));
+           V3_Free(route);    
+       }
+    }
+
+    v3_unlock_irqrestore(vnet_state.lock, flags);
+}
 
 /* At the end allocate a route_list
  * This list will be inserted into the cache so we don't need to free it
@@ -400,14 +421,11 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) {
 
 #ifdef CONFIG_DEBUG_VNET
    {
-       struct eth_hdr * hdr = (struct eth_hdr *)(pkt->header);
-       char dest_str[100];
-       char src_str[100];
-
-       mac_to_string(hdr->src_mac, src_str);  
-       mac_to_string(hdr->dst_mac, dest_str);
        int cpu = V3_Get_CPU();
-       PrintDebug("Vnet: on cpu %d, HandleDataOverLink. SRC(%s), DEST(%s), pkt size: %d\n", cpu, src_str, dest_str, pkt->size);
+       PrintDebug("VNET-core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n",
+                 cpu, pkt->size, pkt->src_id, 
+                 pkt->src_type, pkt->dst_id, pkt->dst_type);
+       //v3_hexdump(pkt->data, pkt->size, NULL, 0);
    }
 #endif
 
@@ -416,7 +434,7 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) {
     look_into_cache(pkt, &matched_routes);
        
     if (matched_routes == NULL) {  
-       PrintError("Vnet: send pkt Looking into routing table\n");
+       PrintDebug("Vnet: send pkt Looking into routing table\n");
        
        matched_routes = match_route(pkt);
        
@@ -434,40 +452,41 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) {
     PrintDebug("Vnet: send pkt route matches %d\n", matched_routes->num_routes);
 
     for (i = 0; i < matched_routes->num_routes; i++) {
-        struct vnet_route_info * route = matched_routes->routes[i];
+       struct vnet_route_info * route = matched_routes->routes[i];
        
         if (route->route_def.dst_type == LINK_EDGE) {
-            struct vnet_brg_dev *bridge = vnet_state.bridge;
+           struct vnet_brg_dev *bridge = vnet_state.bridge;
             pkt->dst_type = LINK_EDGE;
             pkt->dst_id = route->route_def.dst_id;
 
-            if (bridge == NULL || (bridge->active == 0)) {
-               PrintError("VNET: No active bridge to sent data to links\n");
+           if (bridge == NULL || (bridge->active == 0)) {
+               PrintDebug("VNET: No active bridge to sent data to\n");
                continue;
-            }
+           }
 
-            if(bridge->brg_ops.input(bridge->vm, pkt, bridge->private_data) == -1){
+           if(bridge->brg_ops.input(bridge->vm, pkt, bridge->private_data) < 0){
                 PrintDebug("VNET: Packet not sent properly to bridge\n");
                 continue;
-            }         
+           }         
         } else if (route->route_def.dst_type == LINK_INTERFACE) {
-            if (route->dst_dev && route->dst_dev->active){ 
-                 if(route->dst_dev->dev_ops.input(route->dst_dev->vm, pkt, route->dst_dev->private_data) == -1) {
-                       PrintDebug("VNET: Packet not sent properly\n");
-                       continue;
-                 }
-            }
+            if (route->dst_dev == NULL || route->dst_dev->active == 0){
+               PrintDebug("VNET: No active device to sent data to\n");
+               continue;
+            }
+
+           if(route->dst_dev->dev_ops.input(route->dst_dev->vm, pkt, route->dst_dev->private_data) < 0) {
+                PrintDebug("VNET: Packet not sent properly\n");
+                continue;
+           }
         } else {
             PrintError("VNET: Wrong dst type\n");
         }
-
-        PrintDebug("VNET: Forward one packet according to Route %d\n", i);
     }
     
     return 0;
 }
 
-int v3_vnet_add_dev(struct v3_vm_info *vm, uint8_t mac[6], 
+int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t mac[6], 
                    struct v3_vnet_dev_ops *ops,
                    void * priv_data){
     struct vnet_dev * new_dev = NULL;
@@ -485,7 +504,9 @@ int v3_vnet_add_dev(struct v3_vm_info *vm, uint8_t mac[6],
     new_dev->dev_ops.poll = ops->poll;
     new_dev->private_data = priv_data;
     new_dev->vm = vm;
-    new_dev->dev_id = 0;       
+    new_dev->dev_id = 0;
+    new_dev->active = 1;
+    new_dev->mode = GUEST_DRIVERN;
 
     flags = v3_lock_irqsave(vnet_state.lock);
 
@@ -498,7 +519,7 @@ int v3_vnet_add_dev(struct v3_vm_info *vm, uint8_t mac[6],
 
     /* if the device was found previosly the id should still be 0 */
     if (new_dev->dev_id == 0) {
-       PrintError("Device Alrady exists\n");
+       PrintError("Device Already exists\n");
        return -1;
     }
 
@@ -508,6 +529,49 @@ int v3_vnet_add_dev(struct v3_vm_info *vm, uint8_t mac[6],
 }
 
 
+
+int v3_vnet_del_dev(int dev_id){
+    struct vnet_dev * dev = NULL;
+    unsigned long flags;
+
+    flags = v3_lock_irqsave(vnet_state.lock);
+       
+    dev = find_dev_by_id(dev_id);
+    if (dev != NULL){
+       list_del(&(dev->node));
+       del_routes(dev_id);
+    }
+       
+    v3_unlock_irqrestore(vnet_state.lock, flags);
+
+    V3_Free(dev);
+
+    PrintDebug("Vnet: Remove Device: dev_id %d\n", dev_id);
+
+    return 0;
+}
+
+
+static void free_devices(){
+    struct vnet_dev * dev = NULL; 
+
+    list_for_each_entry(dev, &(vnet_state.devs), node) {
+       list_del(&(dev->node));
+       V3_Free(dev);
+    }
+}
+
+static void free_routes(){
+    struct vnet_route_info * route = NULL; 
+
+    list_for_each_entry(route, &(vnet_state.routes), node) {
+       list_del(&(route->node));
+       list_del(&(route->match_node));
+       V3_Free(route);
+    }
+}
+
+
 void  v3_vnet_poll(struct v3_vm_info * vm){
     struct vnet_dev * dev = NULL; 
     struct vnet_brg_dev *bridge = vnet_state.bridge;
@@ -604,3 +668,17 @@ int v3_init_vnet() {
 
     return 0;
 }
+
+
+void v3_deinit_vnet(){
+
+    v3_lock_deinit(&(vnet_state.lock));
+
+    free_devices();
+    free_routes();
+
+    v3_free_htable(vnet_state.route_cache, 1, 1);
+    V3_Free(vnet_state.bridge);
+}
+
+