| 1 | from django.db import models |
|---|
| 2 | |
|---|
| 3 | # Create your models here. |
|---|
| 4 | class Node(models.Model): |
|---|
| 5 | ip = models.IPAddressField() |
|---|
| 6 | port=models.IntegerField() |
|---|
| 7 | floor=models.IntegerField() |
|---|
| 8 | num=models.IntegerField() |
|---|
| 9 | |
|---|
| 10 | """ |
|---|
| 11 | Constructor defines its internal ip address and port number for the node |
|---|
| 12 | @param floor: The floor for the node |
|---|
| 13 | @param num: The number of the node |
|---|
| 14 | """ |
|---|
| 15 | def __init__(self, thisFloor, thisNum): |
|---|
| 16 | ip = getIP(thisFloor, thisNum) |
|---|
| 17 | port = getPort(thisFloor,thisNum) |
|---|
| 18 | floor = thisFloor |
|---|
| 19 | num = thisNum |
|---|
| 20 | |
|---|
| 21 | def __unicode__(self): |
|---|
| 22 | return unicode("node_id: ".__add__(self.floor).__add__("-").__add__(self.num)) |
|---|
| 23 | |
|---|
| 24 | """Calculates the internal ip address of the node based on the ICTAS floor and number |
|---|
| 25 | |
|---|
| 26 | @param floor: The floor of ICTAS where the node is located |
|---|
| 27 | @param num: The number of the node on the particular floor |
|---|
| 28 | @return: The port number used in the CORNET server to access the node; exception if params are not in the range |
|---|
| 29 | """ |
|---|
| 30 | def getIP(self, floor, num): |
|---|
| 31 | if floor > 0 and floor < 5: |
|---|
| 32 | if num > 0 and num < 13: |
|---|
| 33 | ip_num=floor*12-2+num |
|---|
| 34 | return "192.168.1.".__add__(str(ip_num)) |
|---|
| 35 | else: |
|---|
| 36 | raise Exception("Num input must be greater than 0 and less than 13") |
|---|
| 37 | else: |
|---|
| 38 | raise Exception("Floor input must be greater than 0 and less than 5") |
|---|
| 39 | |
|---|
| 40 | """Calculates the port number based on the floor and node number of the floor |
|---|
| 41 | |
|---|
| 42 | @param floor: The floor of ICTAS where the node is located |
|---|
| 43 | @param num: The number of the node on the particular floor |
|---|
| 44 | @return: The port number used in the CORNET server to access the node; exception if params are not in the range |
|---|
| 45 | """ |
|---|
| 46 | def getPort(self, floor, num): |
|---|
| 47 | if floor > 0 and floor < 5: |
|---|
| 48 | if num > 0 and num < 13: |
|---|
| 49 | port_num=(floor-1)*12+num |
|---|
| 50 | return 7000+port_num |
|---|
| 51 | else: |
|---|
| 52 | raise Exception("Num input must be greater than 0 and less than 13") |
|---|
| 53 | else: |
|---|
| 54 | raise Exception("Floor input must be greater than 0 and less than 5") |
|---|