Example #1
0
 def test_access_allowed_expired(self, fake_am):
     # expired entry
     dev = TrafficControlledDevice(controllingIP='1.1.1.1',
                                   controlledIP='2.2.2.5')
     assert not fake_am.access_allowed(dev)
     # Allowed in non-secure mode
     fake_am.secure = False
     assert fake_am.access_allowed(dev)
Example #2
0
 def test_access_allowed_non_existent(self, fake_am):
     # entry does not exist
     dev = TrafficControlledDevice(controllingIP='1.1.1.1',
                                   controlledIP='2.2.2.2')
     assert not fake_am.access_allowed(dev)
     # Allowed in non-secure mode
     fake_am.secure = False
     assert fake_am.access_allowed(dev)
Example #3
0
def test_shaping():
    return TrafficControl(
        device=TrafficControlledDevice(controlledIP=test_ipaddr),
        timeout=86400,
        settings=TrafficControlSetting(down=Shaping(
            delay=Delay(delay=197, ),
            rate=81,
        ),
                                       up=Shaping(
                                           delay=Delay(delay=197, ),
                                           rate=81,
                                       )))
Example #4
0
    def post(self, request, service, address=None):
        '''
        Authorizes one address to shape another address,
        based on the provided auth token.
        '''
        if address is None:
            return Response({'details': 'no address provided'},
                            status=status.HTTP_400_BAD_REQUEST)
        controlled_ip = address

        controlling_ip = get_client_ip(request)

        if 'token' not in request.data:
            token = None
        else:
            token = AccessToken(token=request.data['token'])

        dev = TrafficControlledDevice(controlledIP=controlled_ip,
                                      controllingIP=controlling_ip)

        worked = service.requestRemoteControl(dev, token)

        if not worked:
            return Response(
                {'details': 'invalid token provided'},
                status=status.HTTP_401_UNAUTHORIZED,
            )

        print 'Worked:', worked

        data = {
            'controlling_ip': controlling_ip,
            'controlled_ip': controlled_ip,
        }

        return Response(data, status=status.HTTP_200_OK)
Example #5
0
def _tuple_to_dev(tup):
    return TrafficControlledDevice(
        controllingIP=tup[0],
        controlledIP=tup[1],
    )
Example #6
0
 def _make_tc_device(self, ip='1.1.1.1'):
     tc = TrafficControl()
     tc.device = TrafficControlledDevice(ip, ip)
     return tc
Example #7
0
def _make_device(controlling, controlled=None):
    return TrafficControlledDevice(controllingIP=controlling,
                                   controlledIP=controlled)
Example #8
0
 def test_access_allowed_expired(self, fake_am):
     # expired entry
     dev = TrafficControlledDevice(controllingIP='1.1.1.1',
                                   controlledIP='2.2.2.5')
     assert not fake_am.access_allowed(dev)
Example #9
0
 def test_access_allowed_valid(self, fake_am):
     # valid entry
     dev = TrafficControlledDevice(controllingIP='1.1.1.1',
                                   controlledIP='2.2.2.1')
     assert fake_am.access_allowed(dev)
Example #10
0
    parser.add_argument('--self',
                        action='store_true',
                        help='Shape for oneself?')
    parser.add_argument('--controlling-ip',
                        default='1.1.1.1',
                        help='Controlling ip [%(default)s]')
    parser.add_argument('--controlled-ip',
                        default='2.2.2.2',
                        help='Controlled ip [%(default)s]')
    return parser.parse_args()


if __name__ == '__main__':
    options = parse_arguments()
    client = getAtcClient()
    dev = TrafficControlledDevice(controllingIP=options.controlling_ip,
                                  controlledIP=options.controlling_ip
                                  if options.self else options.controlled_ip)
    settings = TrafficControlSetting(
        up=Shaping(rate=100, ),
        down=Shaping(rate=200, ),
    )
    print settings
    tc = TrafficControl(
        device=dev,
        settings=settings,
        timeout=1000,
    )

    print client.startShaping(tc)